Xaml WP7 usercontrol-方向更改时更改控件宽度

Xaml WP7 usercontrol-方向更改时更改控件宽度,xaml,windows-phone-7,user-controls,orientation,windows-phone,Xaml,Windows Phone 7,User Controls,Orientation,Windows Phone,在我的一个应用程序中,我有一个名为FeedControl的用户控件(是的,它是另一个RSS阅读器!),非常简单——只需一个复选框来选择项目,一个文本块来显示提要名称,另一个文本块来显示未读提要项目的数量。在启动时将提要加载到一个可观察的集合中时,我为每个提要创建了一个控件实例,并将它们全部添加到一个列表框中——这真是非常简单的事情 XAML代码如下: <UserControl x:Class="MyReader.FeedControl" xmlns="http://schemas.micr

在我的一个应用程序中,我有一个名为FeedControl的用户控件(是的,它是另一个RSS阅读器!),非常简单——只需一个复选框来选择项目,一个文本块来显示提要名称,另一个文本块来显示未读提要项目的数量。在启动时将提要加载到一个可观察的集合中时,我为每个提要创建了一个控件实例,并将它们全部添加到一个列表框中——这真是非常简单的事情

XAML代码如下:

<UserControl x:Class="MyReader.FeedControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"             
Loaded="UserControl_Loaded" >

<Grid x:Name="LayoutRoot" Height="50" Background="Black" HorizontalAlignment="Left" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="70"/>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="70"/>
    </Grid.ColumnDefinitions>
    <CheckBox Name="Select" Grid.Column="0" IsChecked="{Binding IsSelected}" Margin="-5,-16" Checked="Select_Checked" Background="White"/>
    <TextBlock Name="FeedName" Grid.Column="1" Text="{Binding FeedName}" Opacity="1" Margin="-20" VerticalAlignment="Center" FontSize="24" 
               MouseLeftButtonUp="FeedName_MouseLeftButtonUp" Height="32" Width="360"/>
    <TextBlock Name="UnreadItems" Grid.Column="2" Text="{Binding UnreadItems}" Opacity="1" Padding="2" VerticalAlignment="Center" HorizontalAlignment="Right" 
               FontSize="24" MouseLeftButtonUp="FeedName_MouseLeftButtonUp" />
</Grid>
然而,这也不起作用(无论我怎么做),所以我对如何最好地做到这一点感到困惑。。。我知道一定有一个非常简单的方法,但到目前为止我还没有找到

有人能给我指一下正确的方向吗

迈克


PS对不起,这篇文章太长了。。。这么简单的问题就这么久了

在您放置此控件的位置,您没有被提及。我想你是把这个控件放在一个电话页面里;就像放置任何其他控件一样。如果是这样,您可以更好地管理该页面(容器页面)中与方向相关的内容,而不是在控件中进行调整。我想这会解决你的问题

您应该为您控制的ListBoxItems设置
水平对齐
水平内容对齐
水平对齐
拉伸。此外,设置控件的设计宽度/设计高度

下面是我在列表框中的一个控件的示例,它以横向模式拉伸

<UserControl x:Class="SabWatch.Resources.Controls.ProgressBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot" Style="{StaticResource AppBackgroundStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

    </Grid>
</UserControl>

列表框(包含我的控件多次出现)如您所怀疑的那样位于正常的电话页面上,但我看不出您的回答会有什么帮助对不起。。。具体来说,你所说的“更好地管理与入职培训相关的工作”是什么意思?控件中文本块的宽度需要动态更改,我正在尝试找出如何以最佳(或最正确)的方式进行更改。。。你能说得更具体一点吗?顺便说一句,我问这个问题的答案是;)谢谢你,非常感谢。我最终发现在我的网格定义中使用Auto和在用户控件的每个实例中手动更改TextBlock的宽度都有效,但您的方式看起来更精细,所以我将尝试使用它。:-)质量低,注释清晰
<UserControl x:Class="SabWatch.Resources.Controls.ProgressBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="480" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot" Style="{StaticResource AppBackgroundStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

    </Grid>
</UserControl>
var lbi = new ListBoxItem();
            var box = new ProgressBox();
...
            lbi.Tag = queueObject;
            lbi.Content = box;
            lbi.HorizontalAlignment = HorizontalAlignment.Stretch;
            lbi.HorizontalContentAlignment = HorizontalAlignment.Stretch;