English 中文(简体)
我怎么能够把内容提炼给内容提炼者?
原标题:How can I set ContentPropertyAttribute to a Content Presenter?

我有用户控制:SnazzyForm,除了两个边界外,还有一片海面,还有一片海面,还有一片直观者。 NET Framework 3.5以其他方式向它传递了内容,这些表格使用控制刚好罚款。

然而,在将该项目移至4.0之后,我向“不要在类型的物体上添加内容”blah blah blah问候。

因此,控制守则是:

Imports System
Imports System.IO
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.ComponentModel
Public Class SnazzyForm
    Inherits ContentControl

    Public Shared TitleProperty As DependencyProperty = DependencyProperty.Register("Title", GetType(String), GetType(SnazzyForm))

    <Description("Title to display"), _
        Category("Custom")> _
    Public Property Title() As String
        Get
            Return CType(GetValue(TitleProperty), String)
        End Get
        Set(ByVal value As String)
            SetValue(TitleProperty, value)
        End Set
    End Property

    Shared Sub New()
          Insert code required on object creation below this point.
        DefaultStyleKeyProperty.OverrideMetadata(GetType(SnazzyForm), New FrameworkPropertyMetadata(GetType(SnazzyForm)))
    End Sub
End Class

因此,指导这一控制的资源词典中的模板是:

<Style TargetType="{x:Type local:SnazzyForm}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:SnazzyForm}">
                    <ControlTemplate.Resources>
                        <Style TargetType="{x:Type Border}" x:Key="formOuterBorderStyle">
                            <Setter Property="Margin" Value="22,22,22,3" />
                            <Setter Property="Padding" Value="0" />
                            <Setter Property="BorderBrush" Value="{StaticResource BrushBorder}" />
                            <Setter Property="BorderThickness" Value="3" />
                            <Setter Property="Background" Value="{StaticResource BrushBackgroundDark}" />
                            <Setter Property="CornerRadius" Value="20,20,0,0" />
                        </Style>
                        <Style TargetType="{x:Type TextBlock}" x:Key="formTitleStyle">
                            <Setter Property="Foreground" Value="{StaticResource BrushWhiteSmoke}" />
                            <Setter Property="FontFamily" Value="Verdana" />
                            <Setter Property="FontSize" Value="16" />
                            <Setter Property="Padding" Value="11,7,7,7" />
                            <Setter Property="VerticalAlignment" Value="Stretch" />
                            <Setter Property="HorizontalAlignment" Value="Stretch" />
                        </Style>
                        <Style TargetType="{x:Type TextBlock}" x:Key="formBreadcrumbStyle">
                            <Setter Property="Foreground" Value="{StaticResource BrushWhiteSmoke}" />
                            <Setter Property="FontFamily" Value="Verdana" />
                            <Setter Property="FontSize" Value="11" />
                            <Setter Property="Padding" Value="7" />
                            <Setter Property="VerticalAlignment" Value="Stretch" />
                            <Setter Property="HorizontalAlignment" Value="Stretch" />
                        </Style>

                        <Style TargetType="{x:Type Rectangle}" x:Key="formBackgroundRectangleStyle">
                            <Setter Property="Fill" Value="{StaticResource BrushABCLight}" />
                        </Style>

                        <Style TargetType="{x:Type Border}" x:Key="formTitleBorderStyle">
                            <Setter Property="BorderBrush" Value="{StaticResource BrushBlack}" />
                            <Setter Property="BorderThickness" Value="0,0,0,2" />
                        </Style>

                    </ControlTemplate.Resources>
                    <AdornerDecorator d:DesignWidth="640" d:DesignHeight="480">
                        <Grid Width="Auto" Height="Auto">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40"/>
                                <RowDefinition Height="40"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="40"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" FontFamily="Arial" FontSize="18.667" Foreground="#FFE0E0E0" Text="{TemplateBinding Title}" TextWrapping="Wrap" Panel.ZIndex="2" Visibility="Collapsed"/>
                            <Path Fill="Black" Stretch="Fill" Stroke="{x:Null}" Margin="0" VerticalAlignment="Stretch" Height="Auto" Grid.Column="1" Grid.Row="0" Data="M0.5,0.5 L39.5,39.5 0.5,39.5 z"/>
                            <Border Background="Black" Margin="0" VerticalAlignment="Stretch" Height="Auto" Grid.Row="0" CornerRadius="10,0,0,0"/>
                            <!-- <Rectangle Fill="Black" Stroke="Black" Margin="0" VerticalAlignment="Stretch" Height="Auto" Grid.Row="0"/> -->
                            <Rectangle Stroke="{x:Null}" Margin="0" Height="Auto" Opacity="0.5" Grid.ColumnSpan="2" Grid.Row="3" Grid.RowSpan="1">
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF222222" Offset="0"/>
                                        <GradientStop Color="#FFB3B3B3" Offset="1"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Rectangle Fill="Black" Stroke="Black" Margin="0" Grid.ColumnSpan="2" Grid.Row="1"/>
                            <Rectangle Fill="{TemplateBinding Background}" Stroke="Black" Margin="0" Height="Auto" Panel.ZIndex="-7" Grid.ColumnSpan="2" Grid.Row="2" Grid.RowSpan="1"/>
                            <Border x:Name="bdr" Style="{StaticResource formOuterBorderStyle}" Margin="0" Grid.ColumnSpan="2" Grid.RowSpan="3" d:LayoutOverrides="Width, Height" d:IsHidden="True" Visibility="Collapsed"/>
                            <Grid Margin="3" Grid.ColumnSpan="2" Grid.RowSpan="3">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" MinHeight="77" />
                                    <RowDefinition MinHeight="400" />
                                </Grid.RowDefinitions>
                                <Border Style="{StaticResource formTitleBorderStyle}" BorderBrush="{x:Null}">
                                    <StackPanel Margin="0">
                                        <TextBlock Text="{Binding ViewModelFriendlyName}" Style="{StaticResource formTitleStyle}" />
                                        <TextBlock Margin="11,0,0,0" Text="{Binding BreadcrumbTrail}" Style="{StaticResource formBreadcrumbStyle}" />
                                    </StackPanel>
                                </Border>
                                <Rectangle Grid.Row="1" Style="{StaticResource formBackgroundRectangleStyle}" Visibility="Collapsed" />

                                <!--Put the form below here-->
                                <ContentPresenter x:Name="ContentPresenterX" Grid.Row="1" Margin="0" />    
                                <!--Put the form above here-->

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

我怀疑我真的只是想知道,现在我不得不告诉大家,如果我以前知道这是我想要的,那么我为什么要用内容来介绍内容,以及我是如何这样做的。

任何想法?

煤炭

最佳回答

添加<条码> Property=Content} to ContentPresenter

生活津贴 关于这一问题的论坛员额建议,在管制编码中增加内容提要,但我无法工作。

煤炭

问题回答

暂无回答




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签