문제

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 ?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top