문제

이것은 WPF 응용 프로그램입니다.버튼이 NULL이고 CommandParameter가 인식되지 않습니다.나는 이것을 고치는 방법을 모르겠습니다.어떤 아이디어가 있습니까? 이것은 코드입니다.

개인 void button_click (객체 발신자, routedEventArgs 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>
.

도움이 되었습니까?

해결책

CommandParameter를 태그와 보낸 사람을 (프레임 워크웨어) 보낸 사람에게 버튼으로 변경했습니다.

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


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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top