在我的一個應用程序中,我有一個名爲FeedControl的用戶控件(它是另一個RSS閱讀器!),它非常簡單 - 只需一個複選框來選擇項目,顯示一個文本塊供稿名稱和另一個文本塊來顯示未讀供稿項目的數量。在啓動時將這些提要加載到可觀察的集合中,然後爲每個提要創建一個控件實例,並將它們全部添加到列表框中 - 這非常簡單。WP7 usercontrol - 改變方向變化時的控制寬度
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>
當頁面的方向變化的Feedcontrol項目列表框是我想進名文本塊更改爲正確的尺寸(560像素景觀,縱向爲360px),所以我假定通過將網格欄寬度設置爲「*」或「自動」,並設置文本塊沒有寬度,它會自動調整大小,但只調整爲文本寬度而不是全寬。
於是我嘗試了文本塊設置在XAML和頁面方向改變事件我叫下面的方法在FeedControl的每個實例目前ListBox中默認的縱向尺寸(360):
public void ChangeOrientation(bool isLandscape)
{
if (isLandscape)
{
this.LayoutRoot.Width = App.LandscapeWidth; //700
this.FeedName.Width = App.LandscapeItemWidth; //560
}
else
{
this.LayoutRoot.Width = App.PortraitWidth; //480
this.FeedName.Width = App.PortraitItemWidth; //360
}
this.InvalidateArrange();
this.InvalidateMeasure();
}
然而,這也不管用(不管我嘗試什麼),所以我很困惑如何最好地做到這一點......我知道必須有一個非常簡單的方法,但到目前爲止我還沒有找到它。
請問有人可以指點我正確的方向嗎?
邁克
PS對不起後的長度。所以,只要這樣一個簡單的問題!
低質量,注意明確 – 2013-07-30 14:24:33