gpt4 book ai didi

c# - 在 Windows 应用商店应用程序中动态填充组合框

转载 作者:行者123 更新时间:2023-11-30 20:53:48 24 4
gpt4 key购买 nike

我添加了这个控件,我是如何动态分配它的标签和内容的??

<ComboBox x:Name="cbTst" SelectedValue="{Binding SelectedDirection, Mode=TwoWay}" SelectedValuePath="Tag" Canvas.Left="82" Canvas.Top="19">
<ComboBoxItem Content="North" Tag="0"/>
<ComboBoxItem Content="East" Tag="90"/>
<ComboBoxItem Content="South" Tag="180"/>
<ComboBoxItem Content="West" Tag="270"/>
</ComboBox>

最佳答案

        ComboBox cbTst = new ComboBox { Height = 30, Width = 100 };
cbTst.SelectedValue = "{Binding SelectedDirection, Mode=TwoWay}";
cbTst.SelectedValuePath = "Tag";

cbTst.Items.Add(new ComboBoxItem { Content = "North", Tag = 0 });
cbTst.Items.Add(new ComboBoxItem { Content = "East", Tag = 90 });
cbTst.Items.Add(new ComboBoxItem { Content = "South", Tag = 180 });
cbTst.Items.Add(new ComboBoxItem { Content = "West", Tag = 270 });

Gridx.Children.Add(cbTst);

XAML:

   <Grid x:Name="Gridx" Margin="231,162,201,147">
</Grid>

关于c# - 在 Windows 应用商店应用程序中动态填充组合框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19680080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com