4

汎用のカスタム ContentControl を使用する Silverlight アプリケーションに取り組んでいます。この ContentControl には、Generic.xaml で指定されたコントロール テンプレートがあります。

継承された ContentControl のテンプレート...

<Style TargetType="local:ExtContentControl">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:ExtContentControl">
                <Border x:Name="content" Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Child="{TemplateBinding Content}">
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

継承された ComboBox のテンプレート...

<controltemplate targettype="local:ExtComboBox"></controltemplate>

...

<Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Margin="1" Opacity="0" RadiusY="2" RadiusX="2" Stroke="#FF6DBDD1" StrokeThickness="1"/>

インスタンス化されると、ContentControl のコンテンツは、Textbox、Dropdown、Label、または Datepicker の (ジェネリック) コントロールに設定されます。

public class ExtContentControl : ContentControl
{
    public ExtContentControl()
    {
        this.DefaultStyleKey = typeof(ExtContentControl);

        RenderControl();
    }

    private void RenderControl()
    {
        ExtComboBox extComboBox = new ExtComboBox();
        this.Content = extComboBox;
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        Border bor = GetTemplateChild("content") as Border;

        ExtComboBox cmbTest = bor.Child as ExtComboBox;

        //Find FocusVisualElement from ExtComboBox Control Template
        //Rectangle rec = cmbTest.FindName("FocusVisualElement") as Rectangle;
        //cmbTest returns null
    }
}

前回のコメントでわかるように...

//ExtComboBox コントロール テンプレートから FocusVisualElement を検索します //Rectangle rec = cmbTest.FindName("FocusVisualElement") as Rectangle; //cmbTest は null を返します

ContentControl 内の OnApplyTemplate 内から FocusVisualElement を取得するにはどうすればよいですか?

これが理にかなっていることを願っています。

4

1 に答える 1

1

これに対する解決策...

http://www.codeproject.com/Questions/192431/Hover-Foreground-Colour-with-dynamic-binding-Conte.aspx

于 2011-05-10T09:54:07.290 に答える