开发者

Can't access item in ItemsControl

开发者 https://www.devze.com 2023-03-04 15:49 出处:网络
I define my ItemsControl that contain RadioButtons. I want to access the Items contained in ItemsControl that are attached as binding child - and when I try to access the ItemsControl.Items I can\'t

I define my ItemsControl that contain RadioButtons.

I want to access the Items contained in ItemsControl that are attached as binding child - and when I try to access the ItemsControl.Items I can't see the RadioButtons.

The code:

<ItemsControl Name="itemsControl" >
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <RadioButton Content="{Binding Key}" />
        </DataTemplate>
    </ItemsControl开发者_StackOverflow.ItemTemplate>
</ItemsControl>


This is because you are setting the ItemTemplate of the control, ant not its items. To add items do it like this:

<ItemsControl Name="itemsControl" >
    <ItemsControl.Items>
            <RadioButton Content="{Binding Key}" />
    </ItemsControl.Items> 
</ItemsControl>
0

精彩评论

暂无评论...
验证码 换一张
取 消