Question

Ceci est une application WPF.Le bouton est null et le commandalter n'est pas reconnu.Je ne sais pas comment résoudre ce problème.Des idées? Ceci est le code:

VID VID PRIVÉE BOUTON_CLICK (EXPÉLATEUR D'OBJETER, ROUREDETEDEVENTARGS E)

var button = (Button) sender;
var userName = button.CommandParameter;





<TabControl Name="ImTabControl"
                    Width="670"
                    Height="450"
                    Margin="0,10,5,0"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Top"
                    ItemsSource="{Binding}">
            <TabControl.Resources>
                <DataTemplate x:Key="TabHeader" DataType="TabItem">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Margin="0,0,5,0"
                                   HorizontalAlignment="Left"
                                   VerticalAlignment="Center"
                                   Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}},
                                                  Path=Header}" />
                        <Button Name="ImButton"
                                Click="CloseTabButton_OnClick"
                                CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}},
                                                           Path=Name}">
                            <Image Width="7"
                                   Height="7"
                                   Source="../Resources/Images/CloseWindow.png" />
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </TabControl.Resources>
        </TabControl>

Était-ce utile?

La solution

J'ai changé le commandalParameter sur balise et expéditeur sous forme d'expéditeur (FrameworkElement).

Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type TabItem}}, Path=Name}">


var button = (FrameworkElement)sender;
var tabName = button.Tag as string;

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top