windows-phone-7 - 如何删除WP7中按钮周围的黑色空间?

标签 windows-phone-7 silverlight-3.0 windows-phone-7.1

如我所见,WP7按钮周围有一些像素的黑色空间。
我如何将其删除?

我读过this帖子,但没有设法删除它!您能举个可行的例子吗?

我尝试用<Border... />元素包装按钮,但是没有用。

这是我的XAML

<ItemsControl Name="icCells" Grid.Row="1">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Background="Red" BorderThickness="0"  Width="40" Height="40" BorderBrush="Green" Padding="0" Margin="0" />

                </DataTemplate>                   
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <toolkit:WrapPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>

谢谢

最佳答案

请尝试以下方法:

风格

<phone:PhoneApplicationPage.Resources>
    <Style x:Key="CustomButtonStyle" TargetType="Button">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
        <Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
        <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid Background="Transparent">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="0">
                            <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</phone:PhoneApplicationPage.Resources>

XAML
<Button Style="{StaticResource CustomButtonStyle}"/>

如果要更改“边距”(我将其设置为0),请在“样式”中搜索以下内容:
Margin="0"

如果要更改填充(我将其设置为0),请在“样式”中搜索以下内容:
"Padding" Value="0"

我确实建议将其更改为更小...我个人认为它的填充量要大到多

关于windows-phone-7 - 如何删除WP7中按钮周围的黑色空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8966232/

相关文章:

silverlight - 浏览器外的 Silverlight 应用程序 - 如何设置自动更新?

windows-phone-7 - 使用WP7.1 XNA项目中的WP7 XNA库作为引用

c# - 长时间运行函数的进度条 WP7 C#

c# - 在 Windows Phone 7 的 MVVM 应用程序中使用 REST Web 服务的良好架构?

c# - 在 Windows Phone 7 (WP7) 中以编程方式创建按钮

silverlight - 如何禁用 Silverlight 3 子窗口上的退出按钮?

ios - iOS 所需的 Windows Phone 7 页面转换/翻转卡片动画

c# - 如何替换 RichTextBox 中的超链接链接(Windows 手机)

database - Windows Phone 7 - 将现有数据库加载到独立存储中

c# - 循环和更改列表 - 删除并不总是有效