Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Button 如何捕捉;菜单项1“;下拉按钮中的文本并指定给文本框_Button_Drop Down Menu - Fatal编程技术网

Button 如何捕捉;菜单项1“;下拉按钮中的文本并指定给文本框

Button 如何捕捉;菜单项1“;下拉按钮中的文本并指定给文本框,button,drop-down-menu,Button,Drop Down Menu,我使用的代码片段来自下拉按钮的codeproject < m:SplitButton Content="TWB" Name="btnSearch" Grid.Row="0" Grid.Column="0" Style="{StaticResource aeroNormalColorSplitButtonStyle}" Click=

我使用的代码片段来自下拉按钮的codeproject

<    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>
所以,在这个拆分按钮旁边,我有一个文本框(基本上是一个搜索框)。因此,由于上面的代码片段显示了两个菜单项“TWB”和“PWB”,当从下拉按钮中选择TWB时,我必须填充文本框,并且按钮上也应该显示相同的文本(TWB)

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

请帮帮我

谢谢,,
Ramm

我尝试将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+=newroutedeventhandler(btnSearch\u Click); TransitionKind.SelectionChanged+=新系统.Windows.Controls.SelectionChangedEventHandler(TransitionKind\u SelectionChanged)

私有无效转换种类\u选择已更改(对象发送方,选择已更改的发送方) { btnSearch.Content=((ListBoxItem)TransitionKind.SelectedItem.Content; txtBxSearch.Text=“Search”+(string)btnSearch.Content; }

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

<    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>
谢谢,, 撞击