-1

XAML 代码如下:

<Helper:BooleanVisibilityValueConverter x:Key="BoolToVisible" />
   <Control x:Name="ResizeDecorator" MouseMove="ResizeDecorator_MouseMove" Template=" {StaticResource ResizeDecoratorTemplate}" Visibility="{Binding IsButtonVisible,Converter= {StaticResource ResourceKey=BoolToVisible},RelativeSource={RelativeSource  TemplatedParent}}" />
<Helper:BooleanVisibilityValueConverter x:Key="BoolToVisible" />
<Control x:Name="ResizeDecorator"  MouseMove="ResizeDecorator_MouseMove" Template="{StaticResource ResizeDecoratorTemplate}" Visibility="{Binding IsButtonVisible,Converter={StaticResource ResourceKey=BoolToVisible},RelativeSource={RelativeSource TemplatedParent}}"  />

视图模型代码:

private bool _IsButtonVisible;
public bool IsButtonVisible
{
    get { return _IsButtonVisible; }
    set
    {
        _IsButtonVisible = value;
        NotifyPropertyChanged("IsButtonVisible");
    }
}

IsButtonVisible =false;

谁能告诉我我哪里出错了?

4

1 回答 1

2

我猜问题是您在模板化父级上绑定到 IsButtonVisible。相反,您需要绑定到模板化父级的 ViewModel/DataContext 上的 IsButtonVisible - 即

Visibility="{Binding DataContext.IsButtonVisible,Converter={StaticResource ResourceKey=BoolToVisible},RelativeSource={RelativeSource TemplatedParent}}"
于 2012-05-07T11:02:12.553 回答