【问题标题】:how to capture the "Menu Item 1" text in the dropdown button and assign to textbox如何在下拉按钮中捕获“菜单项 1”文本并分配给文本框
【发布时间】:2009-07-24 18:09:14
【问题描述】:

我正在使用下拉按钮的代码项目中的代码 sn-p。

<    m:SplitButton Content="TWB" Name="btnSearch"
                          Grid.Row="0" Grid.Column="0"
                          Style="{StaticResource aeroNormalColorSplitButtonStyle}"
                          Click="btnSearch_Click" 
                          Width="60" Height="30"
                          VerticalAlignment="Center" 
                          HorizontalAlignment="Left"   
                          Mode="{Binding ElementName=modeSelector, Path=SelectedItem}"
                          Placement="{Binding ElementName=placementSelector, Path=SelectedItem}" MouseLeftButtonDown="btnSearch_MouseLeftButtonDown"
                                MenuItem Header="TWB"/&gt;
                                MenuItem Header="PWB"&gt;
                                /MenuItem&gt;
                          </m:SplitButton>

所以,在这个拆分按钮旁边,我有一个文本框(基本上是一个搜索框)。因此,由于上面的代码 sn-p 将 2 个菜单项显示为“TWB”和“PWB”,当从下拉按钮中选择 TWB 时,我必须填充文本框,并且按钮上也应该显示相同的文本(新台币)。

如果我从下拉按钮中单击 PWB,我应该在按钮上获得“PWB”名称,并且文本框中也应该显示相同的 PWB 名称。

请帮帮我。

谢谢你, 拉姆

【问题讨论】:

    标签: button drop-down-menu


    【解决方案1】:

    我尝试将 ListBox 添加到 SplitButton,现在我可以看到文本框中的文本了。

    将上面的Xaml代码修改为

    <m:SplitButton Content="TWB" Name="btnSearch"
                        Grid.Row="0" Grid.Column="0"
                        Style="{StaticResource aeroNormalColorSplitButtonStyle}"
                        Click="btnSearch_Click" 
                        Width="60" Height="30"
                        VerticalAlignment="Center" 
                        HorizontalAlignment="Left"  
                        Mode="{Binding ElementName=modeSelector, Path=SelectedItem}"
                        Placement="{Binding ElementName=placementSelector, Path=SelectedItem}">
                        <ListBox x:Name="TransitionKind" SelectionChanged="TransitionKind_SelectionChanged">
                            <ListBoxItem Content="TWB"/>
                            <ListBoxItem Content="PWB"/>
                        </ListBox>
                    </m:SplitButton>
    

    在后面的代码中,

    btnSearch.Click += new RoutedEventHandler(btnSearch_Click); TransitionKind.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(TransitionKind_SelectionChanged);

    private void TransitionKind_SelectionChanged(object sender, SelectionChangedEventArgs e) { btnSearch.Content = ((ListBoxItem)TransitionKind.SelectedItem).Content; txtBxSearch.Text = "搜索" + (string) btnSearch.Content; }

    现在,我可以看到文本框中的文本变为单击下拉按钮。

    谢谢你, 拉姆

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      相关资源
      最近更新 更多