質問

誰かが私に役立つ例や説明を教えてくれませんか。

  1. SilverLight オートコンプリート ボックスを拡張して透かしを使用できるようにします。
  2. Watermark TextBox を拡張して、オートコンプリート機能を有効にします。

オプション 1 が最も簡単だと思いますが、オープンです。

前もって感謝します。

役に立ちましたか?

解決

右バット、私はオプション1が良いでしょうね。

1)あなたはAutoCompleteBoxに使用することができますWatermarkTextを保持するために添付プロパティを作成します。

2)AutoCompleteBox(単にブレンドを使用して既存のものをコピーする)ためのコントロールテンプレートを作成しますが、ウォーターマークテキストボックスにテキストボックスを変更し、添付プロパティの値にWatermarkTextBoxのプロパティを設定するためにTemplateBindingのを使用しています。 コントロールテンプレートは(例えばWatermarkedAutoCompleteBoxStyle)スタイルに適用すべきである。

あなたはそれに行くために良いことがあります。 あなたは透かし入りオートコンプリートボックスをしたい任意の時間は、ちょうど添付プロパティの値を設定し、定義されたスタイルを適用します。

あなたがそれらのいずれかのステップのより詳細な説明が必要な場合は、

、ちょうどあなたの手を上げ、私はサンプルを作成するための時間を見つけようとします。

別の方法としては、AutoCompleteBoxから派生する代わりに、添付プロパティのDependencyPropertyにを追加して、/テーマにgeneric.xamlファイルを、スタイルをパッケージ化、それが動作します一度私は通常それを行うことができます。

他のヒント

スティーブの答えに基づきます:

Public Class WatermarkExtender
    Inherits DependencyObject

    Public Shared ReadOnly WatermarkProperty As DependencyProperty =
        DependencyProperty.RegisterAttached(
            "Watermark",
            GetType(Object),
            GetType(WatermarkExtender),
            New UIPropertyMetadata(Nothing))

    Public Shared ReadOnly WatermarkTemplateProperty As DependencyProperty =
        DependencyProperty.RegisterAttached(
            "WatermarkTemplate",
            GetType(DataTemplate),
            GetType(WatermarkExtender),
            New UIPropertyMetadata(Nothing))

    Public Shared Sub SetWatermark(ByVal element As UIElement, ByVal value As Object)
        element.SetValue(WatermarkProperty, value)
    End Sub

    Public Shared Function GetWatermark(ByVal element As UIElement) As Object
        Return element.GetValue(WatermarkProperty)
    End Function

    Public Shared Sub SetWatermarkTemplate(ByVal element As UIElement, ByVal value As Object)
        element.SetValue(WatermarkTemplateProperty, value)
    End Sub

    Public Shared Function GetWatermarkTemplate(ByVal element As UIElement) As Object
        Return element.GetValue(WatermarkTemplateProperty)
    End Function
End Class

スタイル:

<!--  input:AutoCompleteBox  -->
    <Style TargetType="input:AutoCompleteBox">
        ...
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="input:AutoCompleteBox">
                    <Grid Opacity="{TemplateBinding Opacity}">
                        <extk:WatermarkTextBox 
                            Padding="{TemplateBinding Padding}"
                            Background="{TemplateBinding Background}" 
                            IsTabStop="True" 
                            x:Name="Text" 
                            Style="{TemplateBinding TextBoxStyle}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            Foreground="{TemplateBinding Foreground}" 
                            Margin="0" 
                            Watermark="{Binding Path=(local:WatermarkExtender.Watermark), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                            WatermarkTemplate="{Binding Path=(local:WatermarkExtender.WatermarkTemplate), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />

                        ...
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

使用方法:

<Window.Resources>
<Style x:Key="acWatermarkStyle" TargetType="{x:Type wtk:AutoCompleteBox}" BasedOn="{StaticResource {x:Type wtk:AutoCompleteBox}}">
            <Setter Property="local:WatermarkExtender.WatermarkTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock Foreground="Gray" Margin="3,0,0,0" Text="{Binding}" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
</Window.Resources>

<wtk:AutoCompleteBox 
Height="25" 
Margin="2" 
Style="{StaticResource acWatermarkStyle}"
HorizontalAlignment="Stretch"
ValueMemberPath="SomeProp"
FilterMode="Custom" 
local:WatermarkExtender.Watermark="type something" />
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top