2017-02-21 14 views
1

ListViewデータ型に編集可能なテキストブロックのカットオフコントロールを配置したいと考えています。私はthis articleに従っており、うまくいきます。WPFカスタムコントロールがリストビューで期待通りに機能しない

しかし、このコントロールをListviewデータ型に配置すると、Textblockをダブルクリックすると、カスタムコントロールのOnMouseDoubleClickイベントが発生しますが、テキストボックスは表示されません。

私のDataTemplate:

<DataTemplate x:Key="ItemTemplate"> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="auto" /> 
     </Grid.ColumnDefinitions> 

     <StackPanel Orientation="Horizontal" 
          Grid.Column="0"> 
      <Image Source="{Binding Icon}" 
          Margin="0 0 4 0" /> 
      <localp:EditableTextBlock Text="{Binding Tag, Mode=TwoWay}" 
           VerticalAlignment="Center" /> 
     </StackPanel> 
    </Grid> 

<ListView 
    ItemTemplate={StaticResource ItemTemplate} 
    .... /> 

と私はOnMouseDoubleClick EditableTextBlockが発射される理由は知らないが、期待通りに、内側のテキストボックスが表示されることはありません。

おかげで、あなたの助けのために何か他のものに

よろしく

答えて

1

変更ヌルからTextBlockForegroundColorPropertyTextBoxForegroundColorPropertyのデフォルト値進歩である:

public static readonly DependencyProperty TextBlockForegroundColorProperty = 
    DependencyProperty.Register("TextBlockForegroundColor", 
    typeof(Brush), typeof(EditableTextBlock), new UIPropertyMetadata(Brushes.Black)); 

public static readonly DependencyProperty TextBoxForegroundColorProperty = 
    DependencyProperty.Register("TextBoxForegroundColor", 
    typeof(Brush), typeof(EditableTextBlock), new UIPropertyMetadata(Brushes.Black)); 

それともXAMLでそれらを設定します。

<local:EditableTextBlock TextBlockForegroundColor="Black" TextBoxForegroundColor="Black" ... /> 

編集

キーボードフォーカスをTextBoxに設定できますが、e.Handledをtrueに設定するか、OnTextBoxLostFocusがTextBoxを実行して非表示にします。

+0

はい、私はこれをしました(申し訳ありませんが、私が指定していない場合は透明です)。しかし、問題は同じです:リストビューでEditableTextBlockをダブルクリックすると、Textboxは表示されません。ありがとう。 – ArthurCPPCLI

+0

私の編集を参照してください。提供されたリンクのコードを変更していない場合、これは機能します。 – Ron

+0

ああいいです、それは動作します。どうもありがとう :) – ArthurCPPCLI

関連する問題