2012-06-22 6 views
0

내가 만든 사용자 지정 탭 컨트롤이 있지만 문제가 있습니다. 사용자 지정 TabControl보기의 일부로 편집 가능한 TextBox가 있습니다.종속성 속성을 다른 속성에 바인딩

<Controls:EditableTextControl x:Name="PageTypeName" 
            Style="{StaticResource ResourceKey={x:Type Controls:EditableTextControl}}" Grid.Row="0" TabIndex="0" 
            Uid="0" 
            AutomationProperties.AutomationId="PageTypeNameTextBox" 
            AutomationProperties.Name="PageTypeName" 
            Visibility="{Binding ElementName=PageTabControl,Path=ShowPageType}"> 
     <Controls:EditableTextControl.ContextMenu> 
      <ContextMenu x:Name="TabContextMenu"> 
       <MenuItem Header="Rename Page Type" Command="{Binding Path=PlacementTarget.EnterEditMode, RelativeSource={RelativeSource AncestorType=ContextMenu}}" 
          AutomationProperties.AutomationId="RenamePageTypeMenuItem" 
          AutomationProperties.Name="RenamePageType"/> 
       <MenuItem Header="Delete Page Type" Command="{Binding Path=PageTypeDeletedCommand}" 
          AutomationProperties.AutomationId="DeletePageTypeMenuItem" 
          AutomationProperties.Name="DeletePageType"/> 
      </ContextMenu> 
     </Controls:EditableTextControl.ContextMenu> 
     <Controls:EditableTextControl.Content> 
      <!--<Binding Path="CurrentPageTypeViewModel.Name" Mode="TwoWay"/>--> 
      <Binding ElementName="PageTabControl" Path="CurrentPageTypeName" Mode ="TwoWay"/> 
     </Controls:EditableTextControl.Content> 
    </Controls:EditableTextControl> 

콘텐츠 섹션에서 CurrentPageTypeName이라는 종속성 보호 기능에 바인딩됩니다. 이 Depedency 소품은이 사용자 지정 Tab 컨트롤의 일부입니다. 나는 재산을 CurrentPageTypeName하기 위해, 실제 이름 값으로, 그때 내 재산을 결합 사용자 지정을 TabControl을 사용하고 다른보기에서

public static DependencyProperty CurrentPageTypeNameProperty = DependencyProperty.Register("CurrentPageTypeName", typeof(object), typeof(TabControlView)); 
    public object CurrentPageTypeName 
    { 
     get { return GetValue(CurrentPageTypeNameProperty) as object; } 
     set { SetValue(CurrentPageTypeNameProperty, value); } 
    } 

는 아래와 같이 :

<Views:TabControlView Grid.Row="0" Name="RunPageTabControl" 
          TabItemsSource="{Binding RunPageTypeViewModels}"        
          SelectedTab="{Binding Converter={StaticResource debugConverter}}" 
          CurrentPageTypeName="{Binding Path=RunPageName, Mode=TwoWay}" 
          TabContentTemplateSelector="{StaticResource tabItemTemplateSelector}" 
          SelectedIndex="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedTabIndex}" 
          ShowPageType="Hidden" >   
     <!--<Views:TabControlView.TabContentTemplate> 
      <DataTemplate DataType="{x:Type ViewModels:RunPageTypeViewModel}"> 
       <RunViews:RunPageTypeView/> 
      </DataTemplate> 
     </Views:TabControlView.TabContentTemplate>--> 

    </Views:TabControlView> 

내 문제는 아무것도 보인다 없다는 것입니다 일어날 수 있습니다. 그것은 내 Chained Dependency Props가 아니라 Itemsource에서 Content를 가져옵니다. 나는 가능한 것을 시도하고 있는가? 그렇다면, 내가 뭘 잘못했는지.

감사합니다.

+0

'PageTabControl'의'x : Name'을 볼 수 없으므로'ElementName = "PageTabControl"bindings가 실패 할 것이라고 상상할 수 있습니다. . 또한 'Itemsource'와 'Itemsource'에서 콘텐츠를 가져 오는 것이 무엇인지 물어볼 수 있습니까? –

답변

1

내가 뭔가를 놓치지 않는 한, 이것은 확실히 가능합니다. 다음은 간단한 작업 예제입니다. 이 속성에 바인딩 텍스트 상자를 포함 TestValue라는 종속성 속성과

사용자 제어 :

<UserControl x:Class="TestApp.TestControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" 
      x:Name="TestControlName"> 
    <Grid> 
    <TextBox Text="{Binding ElementName=TestControlName, Path=TestValue, Mode=TwoWay}"/> 
    </Grid> 
</UserControl> 

뭔가 상술 종속성 속성 결합이 사용자 제어를 이용하여 다른 뷰 :

<Window x:Class="TestApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:TestApp="clr-namespace:TestApp" Title="MainWindow" 
     Height="350" Width="525"> 
    <StackPanel> 
    <TestApp:TestControl TestValue="{Binding ElementName=SourceTextBox, Path=Text, Mode=TwoWay}" /> 
    <TextBox Name="SourceTextBox" /> 
    </StackPanel> 
</Window> 

게시하지 않은 코드 부분에 문제가 있음을 알 수 있습니다 (예 : 콘텐츠 바인딩에 잘못된 이름 사용).

0

"SelectedIndex"속성에 대해 이미이 문제를 해결했다고 생각합니다. 그냥 "CurrentPageType"속성에 대해 똑같은 일을하십시오. 예 : RelativeSource

관련 문제