日期:2014-05-17  浏览次数:20753 次

|ZYCWPF| 为什么自定义控件后,在XAML中写的属性无效呢?而且加了滚动条,但没有出现?谢谢
这是我的ZRichTextBox的自定义样式

    <Style TargetType="{x:Type control:ZRichTextBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type control:ZRichTextBox}">
                    <DockPanel LastChildFill="True">
                        <Border DockPanel.Dock="Top" SnapsToDevicePixels="True"
                            BorderBrush="{TemplateBinding ToolbarBorderBrush}"
                            BorderThickness ="{TemplateBinding ToolbarBorderThickness}">
                            <StackPanel Height="24" Orientation="Horizontal"
                                Background="{TemplateBinding ToolbarBackground}">
                            .....这里为我的工具栏按钮
                            </StackPanel>
                        </Border>
                        <ScrollViewer x:Name="PART_ContentHost" VerticalScrollBarVisibility="Auto"  HorizontalScrollBarVisibility="Auto">
                        </ScrollViewer>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

然后我XAML中用
<zc:ZRichTextBox x:Name="richTextBox" Background="#FFD2CB84" >
发现问题
1:Background="#FFD2CB84" 对RichTextBox不起效果
2:RIchTextBox内容多的时候还是不会出现滚动条

谢谢
------解决方案--------------------
1。 ScrollViewer改成:

    <ScrollViewer x:Name="PART_ContentHost" VerticalScrollBarVisibility="Auto"  HorizontalScrollBarVisibility="Auto"