我正在尝试使用StackPanel控件来显示一些概述选项。当MinWindowWidth大于768px时,我需要让这个控件使用20%的窗口宽度。当这是在手机上运行时,我需要控件来填充屏幕的宽度。
我尝试按照这个question中的建议,尝试以百分比为单位设置一个值。然而,我得到了错误- "*字符串不能转换为长度“。
这是我的XAML -
<StackPanel x:Name="OverviewStack">
<RelativePanel>
<StackPanel Margin="10" x:Name="User" Orientation="Horizontal">
<Ellipse Margin="5" Width="50" Height="50">
<Ellipse.Fill>
<ImageBrush>
<ImageBrush.ImageSource>
<BitmapImage UriSource="Assets/insp.jpg" />
</ImageBrush.ImageSource>
</ImageBrush>
</Ellipse.Fill>
</Ellipse>
<TextBlock Margin="5" VerticalAlignment="Center" Text="Ajay Kelkar" />
</StackPanel>
<StackPanel Margin="10" x:Name="Options" Orientation="Vertical">
<TextBlock Margin="5" Text="Sample text" />
</StackPanel>
</RelativePanel>
</StackPanel>在UWP中不能使用百分比值吗?还是我做错了什么?
发布于 2016-07-19 15:21:18
您需要确定当前所在的平台,并相应地设置值。这听起来像是一个转换器。因为你只有一个UWP项目,你需要检查你在哪个平台上的转换器。这样的信息可以这样获取:
if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") { //Act accordingly }
所以我想你会喜欢这样做:
public object Convert(object value, Type targetType, object parameter, string language)
{
// bind the width as the value the converter is set upon
var width = double.Parse(value.ToString());
if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile")
{
return width;
}
// You weren't clear exactly regarding the 768px thing so act accordingly here
return width * 0.2d;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}https://stackoverflow.com/questions/32538264
复制相似问题