Hi,@Rezan YILDIZ . Welcome Microsoft Q&A.
A ResourceDictionary can have code behind just like Windows etc. so you could add an event handler and call DragMove from there.
My ResourceDictionary is named Dictionary1.xaml
, so i create a new file named Dictionary1.xaml.cs
.
The code behind file should then look like this.
217613-find.txt
After that you need to add the x:Class
attribute to the Xaml file.
<ResourceDictionary x:Class="AssignClickEventtoButtoninResourceDictionary.Dictionary1"
...>
<Style x:Key="column" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="tb" Text="{Binding}" Margin="10 5" />
<Button x:Name="btnFilter" Content="filter" Click="btnFilter_Click" FontSize="16" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
App.xaml:
<Application.Resources>
<ResourceDictionary Source="Dictionary1.xaml" />
</Application.Resources>
MainWindow.xaml:
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<DataGrid ItemsSource="{Binding ItemsViewSource.View}" ColumnHeaderStyle="{StaticResource column}" />
</Grid>
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread.
[5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html