 |
|
 |
Hi !
I want to bind a DataTable with the RadioListBox.
I used the following code but the Items in my View called all: System.Data.DataRowView
RadioListBox.ItemsSource = this._listService.GetGender().DefaultView;
RadioListBox.SelectedValuePath = "ID";
RadioListBox.DisplayMemberPath = "Gender";
When I replace the RadioListBox with a normal ListBox, the code above shows the right Gender-Elements in the Box? What is my mistake?
|
|
|
|
 |
|
 |
Hi MC,
Try to replace the Content Presente in template with the default value:
<RadioButton.Content>
<ContentPresenter />
</RadioButton.Content>
If you find this article useful, please vote for it.Best regards,
Jaime.
|
|
|
|
 |
|
 |
Many thanks Jaime, this is the solution for this problem!
|
|
|
|
 |
|
 |
Hi,
For various reasons, how can i do a loop like this :
for (int i = 0; i < this.RadioListBox1.Items.Count; i++)
{
// the item i
}
|
|
|
|
 |
|
 |
Hello peug,
I think a good alternative would be:
int i=0;
foreach (var item in ListBox.Items)
{
i++:
}
you can replace ´var´ with some specific type.
Best regards,
Jaime.
|
|
|
|
 |
|
 |
Yes! it's so simple but I began ... thank you
|
|
|
|
 |
|
 |
Hi,
Is there a alternate solution to create the same usercontrol but with checkbutton ?
thanks
|
|
|
|
 |
|
 |
you can do whatever you want with WPF. To replace radio with checkbox, replace the <RadioButton> tag inside the RadioListBox template:
<ListBox ... >
<ListBox.Resources>
<Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<CheckBox x:Name="radio" Click="ItemRadioClick">
<CheckBox.Content>
<ContentPresenter ... />
</CheckBox.Content>
</CheckBox>
Best regards,
Jaime.
|
|
|
|
 |
|
 |
Hi, how can we add a little more space between the RadioButton in the XAML?
|
|
|
|
 |
|
 |
Just Had this :
<ControlTemplate TargetType="ListBoxItem">
<RadioButton x:Name="radio" Click="ItemRadioClick" Height="18" ...
|
|
|
|
 |
|
 |
Hmm, this is a bit complex. You have to modify RadioButton's Template and apply it to the radio button as a Style.
The simplest way is to add a space to the content itself.
Best regards,
Jaime.
|
|
|
|
 |
|
 |
This user control is not working in tab.
|
|
|
|
 |
|
 |
hi,
could you elaborate a bit more?
Best regards,
Jaime.
|
|
|
|
 |
|
 |
Hey,
I was busy with some Database design for during last couple of months so I could not reply you.
The problem here is with tab.
I have radiolistbox control in tab and whenever i am in tab the ItemContainerGenerator is empty so it is not able to check the radiobutton logic in CheckRadioButtons function.
The same thing is working properly without tab.
If you need i can send you demo code or something. But you can try your self by putting the radiolistbox control in tab.
Thanks,
Nash
|
|
|
|
 |
|
 |
hmm, I am really not sure about your issue. A sample app would be useful.
I have recently detected that it is better to use the default content presenter as:
<RadioButton.Content>
<ContentPresenter />
</RadioButton.Content>
Please have a try.Best regards,
Jaime.
|
|
|
|
 |
|
 |
I have demo project related to this bug. I am not sure how to send it to you.
I am writing here what i did..
(1)Download your demo project.
(2)Add tab and put all controls in tab.
(3)on window load Added new line selectedindex=3 as below
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.RadioListBox1.IsTransparent = false;
this.RadioListBox1.SelectedIndex = 3;
this.Button1_Click(this, null);
}
(4)Run and i was expecting thhat the radiolistbox should selected item index 4 and the checkbox should be checked.
The lable shows "selected value 3"
but the radiobutton is not selected.
I can send you project but I am not sure how to attach it here.
Any suggestion.
Thanks
Naish
|
|
|
|
 |
|
 |
ok Naish,
I think I've got it. I will need some days to test it and will come back to you.Best regards,
Jaime.
|
|
|
|
 |
|
 |
This is just a constructive criticism
There's no need of overriding a ListBox for just checking/unchecking the radio button, you can set selection behavior in XAML like this :
<Style x:Key="{x:Type ListBoxItem}" TargetType="ListBoxItem">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<RadioButton x:Name="radio" Click="ItemRadioClick" IsChecked={Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected, Mode=TwoWay}>
<RadioButton.Content>
<ContentPresenter ... />
</RadioButton.Content>
</RadioButton>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|
 |
|
 |
I have tried many alternatives back and forth from xaml to C#
I found that setting the IsSelected property for an item doesn't fire the SelectedItem event.
Any deeper analysis is welcomed.
Best regards,
Jaime.
|
|
|
|
 |
|
 |
Hi Jaime,
I've downloaded your sample code and make my "recommended" change, and it works
The SelectionChanged event is (correctly) handled and dispatched to your "RadioListBox_SelectionChanged" handler. Either through a single click or code (setting manually the SelectedItem).
I know there are issues about how SelectionChanged is dispatched in composite ListBoxItem, many because everyone uses Selector.IsSelected which is binded only one time. But the solution I gave you is one of those that are working.
You can also use a Trigger on Selector.IsSelected and then set the {radio}.IsChecked property, but direct binding is more elegant for me.
I can send you the modified sample, so that you'll see what I've changed.
Hope this helps,
G.
|
|
|
|
 |
|
 |
Thanks Guillaume,
I had many troubles while trying to derive from Selector. You cannot disable multi-selection. I would like to see your modified version.
Best regards,
Jaime.
|
|
|
|
 |
|
 |
Hi Jaime,
I am facing the problem. My radio button selection is clicking. Can I have your sample code?
My problem is like that.
I have radiolistbox and a combo box. The combo box value is based on the radio list box selection.
But sometime the radiolistbox changed event dosnt fire and that causing my combo box unchanged.
Any suggestion?
|
|
|
|
 |
|
 |
Hey dude! I've got a better solution. Why don't you add radio items into the same group?
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<RadioButton Focusable="False" GroupName="RadioListBoxItems"
IsChecked="{Binding Path=IsSelected, Mode=TwoWay,
RelativeSource={RelativeSource TemplatedParent} }">
<ContentPresenter></ContentPresenter>
</RadioButton>
</ControlTemplate>
</Setter.Value>
</Setter>
...
anhld
|
|
|
|
 |