Question

I think I have the same problem described in this question.

<ItemsControl ItemsSource="{Binding Buttons}">
    ...
    <DataTemplate>
        <RadioButton Style="{StaticResource {x:Type ToggleButton}}"/>
    ...

In this case the static resource is not resolved. I tried changing it to a DynamicResource as per the link above but this doesn't fix the problem. What can I do to access the StaticResource in a DataTemplate ?

Was it helpful?

Solution

If you don't define GroupName for radio buttons, then they will group themselves according to their parent container, i.e. all radios in a single stack panel/grid/dock panel will behave as if they have the same group name. Can you change your UI so that all buttons will reside in the same container?

If that is not possible, define a property of type String on your user control and then bind GroupName (on each radio button) to that property

GroupName="{Binding RelativeSource={RelativeSource FinsAncestor, AncestorType={x:Type my:MyUserControl}}, Path=CurrentGroupName}"

Then, on each instance of the user control, you can set a different group name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top