2

I add this control how i assign it tag and content dynamically ??

<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>
4

2 回答 2

4
        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>
于 2014-01-15T09:02:51.703 回答
0

服务器列表。项目。??

例如,您可以将文本框添加为您的组合框的一个项目

TextBlock tx = new TextBlock();
tx.Text = "something";
cbTst.Items.Add(tx);"

或者您可以像这样删除一个项目: cbTst.Items.RemoveAt(您要删除的项目的索引)

于 2013-10-30T10:53:25.730 回答