2009-08-21 9 views
10

削除ボタンが含まれたWPF UserControlがあります.UserControl全体をCommandParameterとして渡したいと思います。wpf usercontrol、親コントロールにボタンのコマンドパラメータをバインド

現在、バインドはCommandParameter = "{Binding RelativeSource = {RelativeSource Self}}"に設定されていますが、これは私にボタンを与えますが、コントロール全体をどのように取得できますか?

誰でも助けてください。

乾杯、

アンディ

<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> 

答えて

6

は...それを割れ

<Button 
    Grid.Column="2" 
    Style="{DynamicResource CloseButton}" 
    Command="{Binding RemoveCommand}" 
    CommandParameter="{Binding RelativeSource= 
     {RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" 
    Visibility="{Binding RemoveVisible}" 
    /> 
関連する問題