2012-11-08 5 views
0

로컬 윈도우 속성에 의존하여 데이터 격자의 버튼을 표시하거나 축소하려고합니다. 이 LayoutRootTemplate to Root에서 사용하는 Datacontext

<navigation:Page xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="TBPM.PageIssues" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       x:Name="PageIssueRoot" 
... 

에서

다음 항목 작품 _

 <Grid DataContext="{Binding ElementName=PageIssueRoot}"> 
      <Button Click="btnPasteMessage_Click" Visibility="{Binding Path=IsSaving, Converter={StaticResource BoolToVis}}" > 
       <Grid> 
        <Image Height="24" Source="/Next.png" HorizontalAlignment="Center" /> 
       </Grid> 
      </Button> 
     </Grid> 

Codebehind가

#Region "IsSaving" 

    ''' <summary> 
    ''' IsSaving Dependency Property 
    ''' </summary> 
    Public Shared ReadOnly IsSavingProperty As DependencyProperty = _ 
     DependencyProperty.Register("IsSaving", GetType(Boolean), GetType(PageIssues), _ 
      New Windows.PropertyMetadata(False)) 

    ''' <summary> 
    ''' Gets or sets the IsSaving property. This dependency property 
    ''' indicates .... 
    ''' </summary> 
    Public Property IsSaving() As Boolean 
     Get 
      Return CType(GetValue(IsSavingProperty), Boolean) 
     End Get 
     Set(ByVal value As Boolean) 
      SetValue(IsSavingProperty, value) 
     End Set 
    End Property 

#End Region 

는 데이터 그리드 템플릿로 사용하는 경우 동일한 코드가 가 작동하지 않습니다.

해결책은 무엇이며 템플릿이 루트 창을 찾지 못하는 이유는 무엇입니까?

답변

0

... RelativeSource 바인딩을 시도

<Grid DataContext="{Binding ElementName=PageIssueRoot}"> 
     <Button Click="btnPasteMessage_Click" Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Page} Path=IsSaving, Converter={StaticResource BoolToVis}}" > 
      <Grid> 
       <Image Height="24" Source="/Next.png" HorizontalAlignment="Center" /> 
      </Grid> 
     </Button> 
    </Grid>