开发者

WPF DataGridTemplateColumn databind to control outside?

Well i have a control thats placed in a usercontrol and it exposes a ICommand with a DepenceyPropety(ShowCommand), and then i have a datagrid (wpf toolkit) with a few columns and one of them has a delete button

<Custom:DataGrid Margin="0" ItemsSource="{Binding Todos}" AutoGenerateColumns="False">
    <Custom:DataGrid.Columns>
      <Custom:DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
        <Custom:DataGridTemplateColumn>
            <Custom:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Button CommandParameter="{Binding}"
                            Command="{Binding ElementName=ConfirmDeleteDialog, Path=ShowCommand}" 
                            Content="Delete" />
                </DataTemplate>
            </Custom:DataGridTemplateColumn.CellTemplate>
        </Custom:DataGridTemplateColum开发者_高级运维n>
    </Custom:DataGrid.Columns>
</Custom:DataGrid>
<local:ConfirmationDialog x:Name="ConfirmDeleteDialog" 
                          Title="Confirm delete!" 
                          d:LayoutOverrides="Width" 
                          Message="Are you sure that you want to delete the selected todo?" 
                          YesCommand="{Binding DeleteCommand}" />

and as im in a DataTemplate it does not find the element, and i can't combine ElementName and Relative source so how would i define a binding that can access an element declared outside the datatemplate?

The command im trying to bind to is located on ConfirmationDialog.YesCommand..


Well i solved it this way i changed my dialog to a to inherit from ContentControl instead of Control and added a content holder in it..

after that i moved the dialog so it wrapped the whole control, after that i added a routed event that i can listen to and that worked like a charm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜