1

作成したカスタム タブ コントロールがありますが、問題が発生しています。カスタム 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>

Content セクションでは、CurrentPageTypeName という Dependency Prop にバインドしています。この Depedency prop は、このカスタム タブ コントロールの一部です。

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

カスタム TabControl を使用している別のビューでは、次に示すように、実際の名前の値を使用してプロパティを CurrentPageTypeName プロパティにバインドします。

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

私の問題は、何も起こっていないように見えることです。チェーンされた Dependency props からではなく、Itemsource から Content を取得しています。私が試みていることは可能ですか?もしそうなら、私は何を間違えましたか。

ご覧いただきありがとうございます。

4

2 に答える 2

2

私が何かを見逃していない限り、これは間違いなく可能です。これは単純化された作業例です。

このプロパティにバインドされた TextBox を含む、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>

問題は、投稿されていないコードの一部のどこかにあるようです (たとえば、コンテンツ バインディングで使用されている名前が間違っているなど)。

于 2012-06-22T21:13:56.720 に答える
0

I think you already solved this yourself for the "SelectedIndex" property. Just do the same thing for the "CurrentPageType" property i.e. use RelativeSource

于 2012-06-22T21:16:07.700 に答える