I have some radio buttons. The fist one is selected by default.
I need to disable them when processing some data.
Issue: When re-enabling them, the first one is not selected anymore, ie. none selected!
<RadioButton GroupName="ShowSelector" Content="For Selected"
IsChecked="{Binding Path=ShowForSelected, Mode=TwoWay, FallbackValue=True}"
IsEnabled="{Binding NotUnderProcessing}"/>
<RadioButton GroupName="ShowSelector" Content="For All"
IsEnabled="{Binding NotUnderProcessing}"/>
I assume that you have a ViewModel behind your View. When you process your data you have to set the NotUnderProcessing Property and bind your WrapPanel like this:
<RadioButton IsEnabled="{Binding NotUnderProcessing, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
And your ShowForSelected Property might also have the UpdateSourceTrigger in the IsChecked expression.
Edit: When I tried this I run into trouble, I fixed this by making the processing to a Task. Because the ProcessingValue was not setted. And in addition to that I added a Second Property for the second RadioButton and now it's working.
Related
I have my xaml for my windows phone here which has radio button, but sometimes its really confusing.
I am not binding in code behind all done is xaml.
any pointer would be helpful.
here's the code,
<RadioButton Name="rdbChoice1"
Padding="5,0,5,0"
Content="x"
IsChecked="{Binding IsChoice1,Mode=TwoWay}"></RadioButton>
<RadioButtonName="rdbChoice2"
Padding="5,0,5,0"
Content="Not x"
IsChecked="{Binding IsChoice1,Converter={StaticResourceInverseBooleanConverter},Mode=OneWay}"></RadioButton>>
You have to set the group name and that would fix the issue
I have this element in my xaml (DevExpress item):
<dxe:ComboBoxEdit IsTextEditable="False" EditValue="{Binding IDTIPOCONN}"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window},Path=DataContext.ttc}" />
All the binding are correct, and when I change the value, I trigger some event from my ViewModel.
My problem is the update of the value is executed only when I leave the focus of my comboBox. I need, instead, to execute my action when the value is changed, before leaving its foucs.
How can I do it? I need this because selecting one or another from the list, I show to the user some hidden elements.
Try for Binding set UpdateSourceTrigger=PropertyChanged:
<dxe:ComboBoxEdit IsTextEditable="False"
EditValue="{Binding Path=IDTIPOCONN, UpdateSourceTrigger=PropertyChanged}" ... />
In this case, most likely the default value of UpdateSourceTrigger is LostFocus.
I have 2 RadioButton element on each row item of my ListView. If I put the IsChecked attribute on my 2 RadioButton, my WPF application does not allow me to select any of the RadioButton on every row item of my list. Did I miss something? or am I doing it wrong? Please enlighten me.
<StackPanel>
<RadioButton Content="{Binding choice1}" GroupName="{Binding number}" x:Name="btn_radio1" IsChecked="{Binding IsRadioChecked}"></RadioButton>
<RadioButton Content="{Binding choice2}" GroupName="{Binding number}" x:Name="btn_radio2" IsChecked="{Binding IsRadioChecked}"></RadioButton>
</StackPanel>
This code will not work as two radio button with same group name is binded with same IsRadioChecked property, because at a time only one radio button can be checked. if you want both to be checked at a same time its better to use CHECKBOX control
As well as you should use two different IsRadioChecked property IsRadioChecked1 and IsRadioChecked2 in case of checkbox else at both checkbox will have same state
If still you want to use radio button first you decide IsRadioChecked is for choice1 or choice2
if it meant for choice1 remove IsChecked="{Binding IsRadioChecked}" from choice2
I have a grid of CheckBoxes in a WPF C# project. Each CheckBox's Command property is bound to a CheckBoxChangedCommand in my WView.xaml file, like so:
<CheckBox Grid.Row="0" IsChecked="true" x:Name ="CheckBox0"
Command="{Binding CheckBoxChangedCommand}" />
<CheckBox Grid.Row="1" IsChecked="true" x:Name="CheckBox1"
Command="{Binding CheckBoxChangedCommand}" />
Each time one of the CheckBoxes is either checked or unchecked, I call CheckBoxChanged. How would I go about displaying a pop-up window showing either 1. the row number in the grid of the CheckBox and the name of the CheckBox ("CheckBox0", for example) and 2. The Checked value (true/false) for the checkbox?
My CheckBoxChangedCommand, in WViewModel.cs file, looks like this:
public ICommand CheckBoxChangedCommand
{
get
{
return new RelayCommand(param =>
{
MessageBox.Show("CheckBoxChanged!");
});
}
}
How can I access the IsChecked property and the row number of the CheckBox that triggered CheckBoxChanged from withinCheckBoxChanged? How can I pass the data from my View to my ViewModel?
You definitely need to do more with binding here.
First of all, you should probably be binding the IsChecked property of your Checkboxes to a property on your viewmodel.
Second, based on your comment about needing to know the row number of the checkbox that was checked, I'd say you probably need to be generating the "row" including the CheckBox via databinding, so that you can then pass the object that represents the row as the CommandParameter to your CheckBoxChangedCommand.
So something like:
<ListBox ItemsSource="{Binding MyItems}" />
and then in your resources:
<DataTemplate DataType="{x:Type local:MyItemType}">
<CheckBox IsChecked="{Binding IsChecked}"
Command="{Binding CheckChangedCommand}"
CommandParameter="{Binding}" />
</DataTemplate>
Note: Your CheckChangedCommand is probably on the main ViewModel, not the item-level ViewModel, so you probably need to do some other type of lookup to make it find it - this example is just for simplicity
I am working with the the WPF Toolkit DataGrid and currently have a problem with committing data back to the source.
My grid is bound to a CLR object list and I have a converter with both the convert and convert back methods implemented.
The two way binding works fine if the user hits Enter in the cells but if they deselect or tab out of the cells the data that was typed is lost.
I have put a break on the CellEditEnding event and both events for Tab and Enter seem identical, but when it gets to the ConvertBack method on my converter the value is empty.
Any help would be much appreciated.
Try changing the UpdateSourceTrigger parameter of your control's Binding to PropertyChanged instead of the default LostFocus.
Eg
<TextBox
Width="75"
VerticalAlignment="Top"
Margin="10"
Text="{Binding
Source={StaticResource data},
Path=Age,
UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Style="{StaticResource textBoxInError}" />