ScrollViewer的宽度变窄

时间:2019-06-01 02:14:18

标签: wpf xaml scrollviewer

我想在WPF中覆盖ScrollViewer滚动条的宽度。我设法加宽了它的宽度,但是当我尝试使其更薄时却没有效果。似乎它的最小宽度不能被覆盖。下面是我的代码。

为什么下面的代码不能使滚动条的宽度变窄?

谢谢

function checkForNewPosts() {

    $.ajax({
        url: "example.com/ajax.php?method=last_check",
        method: "get",
        dataType:"json",
        success:function(data)
        {
            if(data.last_id>lastCustomerNewsID){
                //Write a new post operation here.

                lastCustomerNewsID = data.last_id;
            }
        }
    });

}

function getNextPage(){
    var html;
    page = page + 1;
    $.ajax({
        url: "example.com/ajax.php?method=list",
        method: "post",
        data:{
            "page": page
        },
        dataType:"json",
        success:function(data)
        {
            //Collate JSON into the required HTML format
            html = "";
            $.each(data.post_list, function(i, item){      
                html = html + "<div class='wall_post'>" + item.contect + "</div>";
            });   
            if(data.last_id>lastCustomerNewsID){
                //Write a new post operation here.
                lastCustomerNewsID = data.last_id;
            }
            if(data.maxpage<=page){
                //If there is no next page 

            }

            $('#wall_posts').prepend(data);
        }
    });
}

setInterval(checkForNewPosts, 10000);

1 个答案:

答案 0 :(得分:0)

您需要编辑模板。

将编辑器光标放在ScrollViewer标记内,然后在属性窗口中转到“其他->模板”,单击右侧的小矩形,然后从弹出菜单中选择“转换为新资源”:

enter image description here

这将创建一个新模板,其中包含一个名为PART_VerticalScrollBar的滚动条。将光标放在该滚动条标签上,然后重复上述操作以将其作为模板,这将创建一个以以下形式开始的控件模板:

    <ControlTemplate x:Key="ScrollBarControlTemplate1" TargetType="{x:Type ScrollBar}">
        <Grid x:Name="Bg" SnapsToDevicePixels="True">
            <Grid.RowDefinitions>
                <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>

现在设置MaxWidth=10(或该Grid元素上的任何内容)。

您可能遇到的唯一其他问题是,如果将其设置得太小,则滚动条按钮上的向上/向下箭头可能会消失,这是因为其默认模板在其路径周围留有空白:

<Path x:Name="ArrowTop" Data="M0,4C0,4 ..etc ... " Fill="#FF606060" Margin="3,4,3,3" Stretch="Uniform"/>

可以通过删除该边距设置和/或将路径完全替换为其他内容来轻松解决。

相关问题