WPF에서는 ItemsControl ControlTemplate에서 이벤트를 어떻게 처리 할 수 있습니까?
-
05-07-2019 - |
문제
ItemsControl ControlTemplate 내부의 이벤트를 처리하려고합니다. 나는 버튼의 마우스 업 및 마우스 딩 이벤트를 할당했습니다 (아래 btnright). 문제는 버튼을 클릭하면 이벤트가 내 코드-비만에 도달하지 않는다는 것입니다. ControlTemplates의 이벤트는 어떻게 작동하며이를 연결하려면 어떻게해야합니까? onapplytemplate 이벤트에서 코드-비인트의 버튼에 이벤트를 할당하려고 시도했습니다.
당신의 도움을 주셔서 감사합니다!
<ItemsControl.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="36" />
<ColumnDefinition />
<ColumnDefinition Width="36" />
</Grid.ColumnDefinitions>
<Button x:Name="btnLeft" Grid.Column="0" Height="36">
<Button.Template>
<ControlTemplate>
<Image>
<Image.Source>
<BitmapImage UriSource="Images\left.png" />
</Image.Source>
</Image>
</ControlTemplate>
</Button.Template>
</Button>
<Border Grid.Column="1" BorderBrush="Black" BorderThickness="1" Background="Black" Padding="6">
<ItemsPresenter Margin="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MarginOffset}" />
</Border>
<Button x:Name="btnRight" Grid.Column="2" Height="36" MouseUp="btnRight_MouseUp" MouseDown="btnRight_MouseDown">
<Button.Template>
<ControlTemplate>
<Image>
<Image.Source>
<BitmapImage UriSource="Images\right.png" />
</Image.Source>
</Image>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</ControlTemplate>
</ItemsControl.Template>
제휴하지 않습니다 StackOverflow