C# Windows Phone xaml标记

C# Windows Phone xaml标记,c#,windows-phone-7,xaml,markup,C#,Windows Phone 7,Xaml,Markup,这个样品有XAML溶液吗?我对显示全名和小点的部分感兴趣。特别是,如果fullname有足够的空间(第一项),我不能将小圆点放在fullname后面 现在,我有这个,但它不合适,因为点总是在右边: <Grid Grid.Row="0" Grid.Column="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <Co

这个样品有XAML溶液吗?我对显示全名和小点的部分感兴趣。特别是,如果fullname有足够的空间(第一项),我不能将小圆点放在fullname后面

现在,我有这个,但它不合适,因为点总是在右边:

    <Grid Grid.Row="0" Grid.Column="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <TextBlock Text="{Binding Path=Title}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
            Margin="0,-16,0,0"
            Style="{StaticResource PhoneTextExtraLargeStyle}" />
        <TextBlock Grid.Column="1" HorizontalAlignment="Right"
            Text="{Binding Path=IsOnline, Converter={StaticResource StatusFormatter}}" Opacity="0.6"
            Style="{StaticResource PhoneTextLargeStyle}"/>
    </Grid>


您可以尝试以下方法:将TextBlock MaxWidth绑定到网格的Widtd减去点的宽度(例如10个像素)。有两种变体:使用转换器或元素绑定。 以下是如何使用元素绑定完成此操作:

首先,我们需要创建具有所需宽度的元素:

<Grid Grid.Row="0" Grid.Column="1"> 
    <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="*"/> 
        <ColumnDefinition Width="10"/> 
    </Grid.ColumnDefinitions> 
    <Border x:Name="TextMaxWidth"/> <!-- this ActualWidth will be equals Grid.Width - 10 -->
</Grid> 
您还可以使用带有点减法宽度的转换器将TextBlock MaxWidth直接绑定到网格实际宽度


Offtop:我以为VK竞赛已经结束了?:)

通过编写自定义面板解决了这个问题:

public class MyStackPanel : Panel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        Size newSize = new Size();
        UIElement firstChild = Children[0];
        UIElement secondChild = Children[1];
        secondChild.Measure(availableSize);
        firstChild.Measure(new Size(availableSize.Width - secondChild.DesiredSize.Width, availableSize.Height));
        newSize.Width = firstChild.DesiredSize.Width + secondChild.DesiredSize.Width;
        newSize.Height = firstChild.DesiredSize.Height;
        return newSize;
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        UIElement firstChild = Children[0];
        UIElement secondChild = Children[1];
        firstChild.Arrange(new Rect(0, 0, firstChild.DesiredSize.Width, firstChild.DesiredSize.Height));
        secondChild.Arrange(new Rect(firstChild.DesiredSize.Width, 0, secondChild.DesiredSize.Width,
                                     firstChild.DesiredSize.Height));
        return base.ArrangeOverride(finalSize);
    }
}
和XAML:

<local:MyStackPanel Grid.Column="1">
    <TextBlock Text="{Binding Path=Title}"
               Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="{Binding Path=IsOnline, Converter={StaticResource StatusFormatter}}"
               Opacity="0.6"
               Style="{StaticResource PhoneTextLargeStyle}"/>
</local:MyStackPanel>


为避免否决票,请发布到目前为止。如果您添加了间隔列定义,它应该会起作用。我无法测试它,因此我不会将其作为答案发布,但语法是:,并使第0列中的文本和第2列中的“点”无效。如果fullname过长,圆点将消失。是否希望圆点始终显示?如果是的话,你想要点在哪里?点代表在线状态。如果有足够的空间容纳屏幕,圆点必须紧跟在全名之后(约翰·多伊),但如果全名太长,圆点必须右对齐(本杰明·华盛顿)是的,比赛结束,但我想完成这件事。为什么边框从第二个代码示例中消失,列定义不同?@Buddy second code sample是第一个代码的延续,您应该一起使用。在第二部分中,您可以用StackPanel
Orientation=“Horizontal”
<local:MyStackPanel Grid.Column="1">
    <TextBlock Text="{Binding Path=Title}"
               Style="{StaticResource PhoneTextExtraLargeStyle}" />
    <TextBlock Text="{Binding Path=IsOnline, Converter={StaticResource StatusFormatter}}"
               Opacity="0.6"
               Style="{StaticResource PhoneTextLargeStyle}"/>
</local:MyStackPanel>