내 MainWindow.xaml의 코드 숨김 파일에서 .xaml 파일의 단추에 액세스하려고합니다. 파일에서 x : Class를 사용하려고했지만 버튼을 사용할 때 작동하지만 다른 많은 오류가 발생합니다. 그래서 나는이 방법을 사용하지 않는 것을 선호한다.<ResourceDictionary>의 WPF 액세스 컨트롤
mainWindows 클래스에서 템플릿을 사용하여 컨트롤에 액세스하는 다른 방법이 있습니까?
코드 :
<ResourceDictionary xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:l="clr-namespace:Avalon.Demo" x:Class="Bildbanken.MainWindow">
<!-- Taggarnas placering under bilderna (Left/ Top/ Right/ Bottom) -->
<Label Content="{Binding Type}" Padding="0,5,7,0" HorizontalAlignment="Right" />
<Label Content="{Binding Category}" Padding="7,0,0,0" />
<ListBox Name="ArtInfo" ItemsSource="{Binding Articles}" BorderThickness="0" Background="{TemplateBinding Background}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="115px" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Artnr}"></TextBlock>
<Button HorizontalAlignment="Right" Name="testbutton" Grid.Column="1">--</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
지정해주십시오. 템플릿의 버튼을 참조하려고하는 이유는 무엇입니까? 나는 틀릴 수도 있지만 99.9 %에서 WPF에서 그런 일을하는 것은 나쁜 습관입니다. – arconaut