0
SearchTextBoxのカスタムスタイルがあります。私はこのコントロールに複数のバインディングを持っています。WPF - カスタムスタイルの子コントロールのプロパティを設定する
<Style TargetType="{x:Type controls:SearchTextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:SearchTextBox}">
<Grid>
<TextBox Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}">
<TextBox.InputBindings>
<KeyBinding Command="{Binding Path=SearchCommand}" Key="Enter" />
<KeyBinding Command="{Binding Path=DeleteSearchCommand}" Key="Esc" />
</TextBox.InputBindings>
</TextBox>
<Button Style="{StaticResource WatermarkButtonCancelStyle}" HorizontalAlignment="Right" Command="{Binding DeleteSearchCommand}" Margin="0,0,22,0"/>
<Button Style="{StaticResource WatermarkButtonSearchStyle}" HorizontalAlignment="Right" Command="{Binding SearchCommand}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
私は右ここに私の見解でテキストボックスを使用しています:
<controls:SearchTextBox Width="300" HorizontalAlignment="Left" Margin="0,0,0,6" />
を、私は私の見解ではなく、スタイルの定義でバインディングを設定するにはどうすればよいです。私は異なるバインディングで複数のビューでコントロールを使用することができますか?カスタムTextBoxのため
異なるオブジェクトを持つ 'DataContext'を設定し、そのままにしておくことができます。または、必要なバインディングごとにSearchTextBoxにプロパティを追加することもできます。 – kusi581
私にコードの例を教えてもらえますか? – user2877820