【问题标题】:Control Template - XAML WinRT Button Padding控件模板 - XAML WinRT 按钮填充
【发布时间】:2015-03-14 19:26:25
【问题描述】:

我开始使用 XAML 作为我空闲时间的一部分,现在我遇到了标准按钮的填充问题。 我有以下代码用于驻留在另一个网格中的网格,所以我的页面中有四个网格,问题是按钮被切断,我无法更改按钮的宽度或填充。

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <TextBlock Text="{Binding Name}" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" FontSize="24"/>
    <Button x:Name="Player2MinusButton" Content="-" Grid.Row="1" Grid.Column="0" FontSize="20" ></Button>
    <Button x:Name="Player2PlusButton" Content="+" Grid.Row="1" Grid.Column="2" FontSize="20" ></Button>
</Grid>

现在的问题是,正如您在此处的屏幕截图中看到的那样,该按钮已被剪切:

我已经尝试设置负填充/边距并制作自定义样式:

<Style TargetType="Button" x:Key="ButtonStyle">
    <Setter Property="Padding" Value="-10,0"/>
</Style>

感谢您的提示,我希望我在第一个问题中没有忘记任何事情。 迈克尔

【问题讨论】:

    标签: c# xaml windows-runtime


    【解决方案1】:

    由于您想要一个比标准按钮更窄的按钮,请设置按钮的 MinWidth 属性:

    <Button x:Name="Player2PlusButton" Content="+" Grid.Row="1" Grid.Column="2" FontSize="20" MinWidth=50 AutomationProperties.Name="Plus Button" ></Button>
    

    如果您复制按钮模板(在设计器中右键单击按钮,然后选择编辑模板...并按照提示操作),您会发现以下内容:

    <x:Double x:Key="PhoneButtonMinHeight">57.5</x:Double>
    <x:Double x:Key="PhoneButtonMinWidth">109</x:Double>
    

    我假设您在手机上运行:Windows 应用商店按钮模板不同,并且没有设置最小值。默认情况下,您的按钮在那里很小。

    【讨论】:

    • 完美,尝试编辑按钮模板,并删除了填充、边距和所有内容,但仍然无法根据内容使按钮的宽度尽可能小,从未想过最重要的是 MinWidth 属性,非常感谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2015-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多