首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UWP :将控件的宽度和高度设置为百分比值

UWP :将控件的宽度和高度设置为百分比值
EN

Stack Overflow用户
提问于 2015-09-12 19:28:24
回答 1查看 2.5K关注 0票数 0

我正在尝试使用StackPanel控件来显示一些概述选项。当MinWindowWidth大于768px时,我需要让这个控件使用20%的窗口宽度。当这是在手机上运行时,我需要控件来填充屏幕的宽度。

我尝试按照这个question中的建议,尝试以百分比为单位设置一个值。然而,我得到了错误- "*字符串不能转换为长度“。

这是我的XAML -

代码语言:javascript
复制
        <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中不能使用百分比值吗?还是我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2016-07-19 15:21:18

您需要确定当前所在的平台,并相应地设置值。这听起来像是一个转换器。因为你只有一个UWP项目,你需要检查你在哪个平台上的转换器。这样的信息可以这样获取:

if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") { //Act accordingly }

所以我想你会喜欢这样做:

代码语言:javascript
复制
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();
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32538264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档