xaml - 在 ItemTemplate 上设置属性

标签 xaml windows-phone-8

当 PivotItem 声明为:

<phone:Pivot Margin="50,0,50,0">
    <phone:PivotItem Margin="0">
        <TextBlock>Text</TextBlock>
    </phone:PivotItem>
</phone:Pivot>

但是我在使用绑定(bind)的时候如何设置Margin:

<phone:Pivot Margin="50,0,50,0">
    <phone:Pivot.ItemTemplate>                    
        <DataTemplate>
            <TextBlock Text="{Binding Body}"/>
        </DataTemplate>
    </phone:Pivot.ItemTemplate>
</phone:Pivot>

如何在 DataTemplate 上设置边距?

最佳答案

您可以尝试使用如下样式:

<phone:Pivot Margin="50,0,50,0">
    <phone:Pivot.ItemTemplate>                    
        <DataTemplate>
            <TextBlock Text="{Binding Body}"/>
        </DataTemplate>
    </phone:Pivot.ItemTemplate>
    <phone:Pivot.ItemContainerStyle>
        <Style TargetType="phone:PivotItem">
            <Setter Property="Margin" Value="0"/>
        </Style>
    </phone:Pivot.ItemContainerStyle>
</phone:Pivot>

关于xaml - 在 ItemTemplate 上设置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21509374/

相关文章:

XAML/C# : What event fires after reordering a gridview?

c# - Windows Phone 8 上的 RestSharp 没有响应

c# - 如何在 Windows Phone 中对 LongListSelector 进行排序

WPF XAML : How to disable multi selection in a DataGrid?

c# - StringFormat 和带标签的多重绑定(bind)

c# - 使用浏览器功能时 WPF 应用程序中的脚本错误

angularjs - 使用 AngularJS 的 Windows Phone 全景图

javascript - 使用 HTML/JavaScript/Apache Cordova 在 Windows Phone 8 上进行页面导航

c# - 隐藏项目时,如何动态地将剩余的堆栈面板元素垂直居中?

wpf - 如何在silverlight中将子元素的宽度绑定(bind)到父元素的宽度