I have three radio buttons bound (with Caliburn.Micro) to three properties of a viewmodel. All the properties seem correct and I debug to see that the selected property is returning True and that the control has IsChecked = true and the property notifiers seem to to be raising ok, but when I first open the form none of the toggle buttons appear selected. If I start clicking them everything works fine, its only on the initial load that the selected value isn't "pressed". This is the XAML...
<RadioButton GroupName="Alignment" Name="FooterLeftAlign" Style="{StaticResource {x:Type ToggleButton}}" Margin="0,0,5,0">
<Image Source="pack://application:,,,/DevExpress.Images.v15.1;component/Images/Format/AlignLeft_16x16.png" Margin="0" />
</RadioButton>
<RadioButton GroupName="Alignment" Name="FooterCenterAlign" Style="{StaticResource {x:Type ToggleButton}}" Margin="0,0,5,0">
<Image Source="pack://application:,,,/DevExpress.Images.v15.1;component/Images/Format/AlignCenter_16x16.png" Margin="0" />
</RadioButton>
<RadioButton GroupName="Alignment" Name="FooterRightAlign" Style="{StaticResource {x:Type ToggleButton}}" Margin="0,0,5,0">
<Image Source="pack://application:,,,/DevExpress.Images.v15.1;component/Images/Format/AlignRight_16x16.png" Margin="0" />
</RadioButton>
And here are the properties...
public bool FooterLeftAlign {
get {
return (ScannerSettings.StampOptions.TextAlign == TextAlignment.Left);
}
set {
if (value) {
ScannerSettings.StampOptions.TextAlign = TextAlignment.Left;
RaisePropertyChanged(() => FooterLeftAlign);
}
}
}
public bool FooterCenterAlign {
get {
return (ScannerSettings.StampOptions.TextAlign == TextAlignment.Center);
}
set {
if (value) {
ScannerSettings.StampOptions.TextAlign = TextAlignment.Center;
RaisePropertyChanged(() => FooterCenterAlign);
}
}
}
public bool FooterRightAlign {
get {
return (ScannerSettings.StampOptions.TextAlign == TextAlignment.Right);
}
set {
if (value) {
ScannerSettings.StampOptions.TextAlign = TextAlignment.Right;
RaisePropertyChanged(() => FooterRightAlign);
}
}
}
I even have some actual ToggleButtons on this form for Bold, Italics, etc... and they work fine. I've seen plenty of examples of forcing custom styles with triggers on it, but I want to make sure it looks like the other toggle buttons. Since I've seen other examples very similar to this the only thing I could think of is the fact we have a DevExpress theme, but couldn't find anything that looked like it would change this behavior.
If anyone has any suggestions it will be greatly appreciated.
You could set ((RadioButton)FooterRightAlign).IsChecked = value
if this is code-behind. If this is actually an MVVM situation, you need to bind each of your radiobuttons to these bools.
<RadioButton GroupName="Alignment" Name="FooterRightAlign" Style="{StaticResource {x:Type ToggleButton}}" IsChecked="{Binding FooterRightAlign, Mode=TwoWay}" Margin="0,0,5,0">
<Image Source="pack://application:,,,/DevExpress.Images.v15.1;component/Images/Format/AlignRight_16x16.png" Margin="0" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.