2009-08-21 30 views
10

Tôi đã có một UserFrol WPF trong đó có một nút loại bỏ, tôi muốn vượt qua toàn bộ UserControl như CommandParameter.wpf usercontrol, ràng buộc tham số lệnh của nút để usercontrol cha mẹ

Hiện tại, ràng buộc được đặt thành CommandParameter = "{Binding RelativeSource = {RelativeSource Self}}" cung cấp cho tôi nút này, nhưng làm cách nào tôi có thể kiểm soát toàn bộ?

Bất kỳ ai có thể hỗ trợ bạn không?

Chúc mừng,

Andy

<UserControl x:Class="GTS.GRS.N3.Controls.LabelledTextBox" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="100" /> 
     <ColumnDefinition Width="155" /> 
     <ColumnDefinition /> 
    </Grid.ColumnDefinitions> 
    <Label Name="label" HorizontalAlignment="Left" Width="96">Label</Label> 
    <TextBox Name="textBox" Grid.Column="1" /> 
    <Button Grid.Column="2" Style="{DynamicResource CloseButton}" Command="{Binding RemoveCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}" Visibility="{Binding RemoveVisible}"></Button> 
</Grid> 
</UserControl> 

Trả lời

6

Cracked nó ...

<Button 
    Grid.Column="2" 
    Style="{DynamicResource CloseButton}" 
    Command="{Binding RemoveCommand}" 
    CommandParameter="{Binding RelativeSource= 
     {RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" 
    Visibility="{Binding RemoveVisible}" 
    /> 
Các vấn đề liên quan