Visual Studio 不显示设计数据 [英] Visual Studio does not show design data

查看:47
本文介绍了Visual Studio 不显示设计数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将设计数据集成到我的 UWP 应用中.对于这种方法,我遵循了微软的步骤:

但我希望结果更像这样:(旧版本,运行时屏幕)

那么我是如何实现的呢?
我决定使用DesignInstance",因为已经有一个以后无论如何都会使用的 ViewModel(目前在运行时运行良好).

因此,我的MockupViewModel"继承了原始的ViewModel并在默认构造函数中创建了虚值:

公共类 MockupModel: 天气视图模型{公共模型模型():基础(){随机随机化器 = new Random();CurrentData.PrecipitationIcon = WeatherUnicodeIconLib.Neutral.Snow;CurrentData.PrecipitationValue = 0.234;CurrentData.SunRiseSetIcon = WeatherUnicodeIconLib.Miscellaneous.SunRise;CurrentData.SunRiseSetTime = DateTime.Now;CurrentData.TemperatureUnitIcon = WeatherUnicodeIconLib.Miscellaneous.Celsius;CurrentData.TemperatureValue = -20.75;CurrentData.WeatherStatusDescription = "lorem ipsum";CurrentData.WeatherStatusIcon = OpenWeatherMapUnicodeStatusIconAdapter.GetStandardIconUnicode(200);CurrentData.WindDirectionDegrees = 240.7;CurrentData.WindSpeedIcon = WeatherUnicodeIconLib.GetBeaufortScaleIcon(3);for (int i = 0; i <7; i++){DailyForecastViewModel NewForecastItem = new DailyForecastViewModel();NewForecastItem.Day = DateTime.Now;NewForecastItem.TemperatureValue = Randomizer.Next(-30, 30);NewForecastItem.WeatherSatusIcon = OpenWeatherMapUnicodeStatusIconAdapter.GetStandardIconUnicode(300);NewForecastItem.WindSpeedIcon = WeatherUnicodeIconLib.GetBeaufortScaleIcon(Randomizer.Next(0, 12));DailyForecast.Add(NewForecastItem);}}}

之后,XAML 代码中添加了 MockupViewModel:
(查看 UserControl 标头/标签的最后一行)

<UserControl.Resources><SolidColorBrush x:Key="FontColor">白色</SolidColorBrush><x:Double x:Key="MainInfoFontSize">90</x:Double><Style TargetType="TextBlock"><Setter Property="FontFamily" Value="{StaticResource WeatherIcons}"/><Setter Property="Foreground" Value="{StaticResource FontColor}"/><Setter Property="FlowDirection" Value="LeftToRight"/><Setter Property="FontSize" Value="30"/></风格></UserControl.Resources><StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"><堆栈面板水平对齐=拉伸"填充="20"><堆栈面板水平对齐=拉伸"方向="水平"FlowDirection="从右到左"><文本块x:Name="SunSetRiseTime"Text="{绑定路径=CurrentData.SunRiseSetTime}"/><文本块x:Name="SunSetRiseIcon"Text="{绑定路径=CurrentData.SunRiseSetIcon}"保证金="10,0,30,0"/><文本块x:Name="WindDirectionIcon"文本="&#xf0b1;"RenderTransformOrigin="0.5 0.5"><TextBlock.RenderTransform><RotateTransform Angle="{Binding Path=CurrentData.WindDirectionDegrees}"/></TextBlock.RenderTransform></TextBlock><文本块x:Name="WindBeaufortScaleIcon"Text="{绑定路径=CurrentData.WindSpeedIcon}"保证金="10,0,30,0"/><文本块x:Name="降水图标"Text="{绑定路径=CurrentData.PrecipitationIcon}"RenderTransformOrigin="0.5 0.5"/><文本块x:Name="PrecipitationIconValue"Text="{绑定路径=CurrentData.PrecipitationValue}"保证金="10,0,20,0"/></StackPanel><堆栈面板x:Name="MainInfos"水平对齐=拉伸"方向="水平"FlowDirection="从右到左"><文本块x:Name="温度单位图标"Text="{绑定路径=CurrentData.TemperatureUnitIcon}"FontSize="{StaticResource MainInfoFontSize}"保证金="0,0,10,0"/><文本块名称="温度值"Text="{绑定路径=CurrentData.TemperatureValue}"FlowDirection="从左到右"FontSize="{StaticResource MainInfoFontSize}"保证金="0,0,40,0"/><文本块x:Name="天气状态图标"Text="{绑定路径=CurrentData.WeatherStatusIcon}"FontSize="{StaticResource MainInfoFontSize}"/></StackPanel><文本块x:Name="天气描述"Text="{绑定路径=CurrentData.WeatherStatusDescription}"文本对齐=右"边距 =0,0,0,20"/><列表框x:Name="每日预测"水平对齐=拉伸"FlowDirection="从右到左"背景=透明"ItemsSource="{绑定路径=DailyForecast}"><ListBox.ItemContainerStyle><Style TargetType="ListBoxItem"><Setter Property="Padding" Value="0"/></风格></ListBox.ItemContainerStyle><ListBox.ItemTemplate><数据模板><堆栈面板x:Name="预测日"方向="水平"Horizo​​ntalAlignment="拉伸"><文本块x:Name="风速"文本对齐=左"Text="{绑定路径=WindSpeedIcon}"宽度=70"/><文本块x:名称=温度"文本对齐=右"文本="{绑定路径=温度值}"宽度=60"/><文本块x:Name="天气图标"文本对齐=中心"Text="{绑定路径=WeatherSatusIcon}"宽度=100"/><文本块x:Name="DayName"文本对齐=左"文本="{绑定路径=天}"宽度=70"/></StackPanel></数据模板></ListBox.ItemTemplate></列表框></StackPanel></StackPanel>

你也可以查看我在github上的项目,获取更详细的代码:

所以我检查了我的项目设置以找出原因,并比较了配置
(发布/调试)

  • 检查优化代码"后(用于调试配置)
  • 重建(重要)

  • --> 不再有无效标记"
  • --> 带有他的数据的 MockupModel 正确显示!

这在VS 2015 社区更新3"和VS 2017 RC"中对我有用

im currently trying to integrate design data in my UWP app. I've followed for this approach the steps from microsoft: https://docs.microsoft.com/en-us/windows/uwp/data-binding/displaying-data-in-the-designer

My problem: The data will not show up. Only the names of the bindings:

But I expect a result more like this: (Older version, screen from runtime)

So how I've implemented it?
I decided to use a "DesignInstance", because there is already a ViewModel which will be later used anyway (wich works currently fine at runtime).

Because of this, my "MockupViewModel" inherits from the original ViewModel and creates imaginary values in the default constructor:

public class MockupModel
    : WeatherViewModel
{
    public MockupModel() : base()
    {
        Random Randomizer = new Random();

        CurrentData.PrecipitationIcon = WeatherUnicodeIconLib.Neutral.Snow;
        CurrentData.PrecipitationValue = 0.234;
        CurrentData.SunRiseSetIcon = WeatherUnicodeIconLib.Miscellaneous.SunRise;
        CurrentData.SunRiseSetTime = DateTime.Now;
        CurrentData.TemperatureUnitIcon = WeatherUnicodeIconLib.Miscellaneous.Celsius;
        CurrentData.TemperatureValue = -20.75;
        CurrentData.WeatherStatusDescription = "lorem ipsum";
        CurrentData.WeatherStatusIcon = OpenWeatherMapUnicodeStatusIconAdapter.GetStandardIconUnicode(200);
        CurrentData.WindDirectionDegrees = 240.7;
        CurrentData.WindSpeedIcon = WeatherUnicodeIconLib.GetBeaufortScaleIcon(3);

        for (int i = 0; i < 7; i++)
        {
            DailyForecastViewModel NewForecastItem = new DailyForecastViewModel();

            NewForecastItem.Day = DateTime.Now;
            NewForecastItem.TemperatureValue = Randomizer.Next(-30, 30);
            NewForecastItem.WeatherSatusIcon = OpenWeatherMapUnicodeStatusIconAdapter.GetStandardIconUnicode(300);
            NewForecastItem.WindSpeedIcon = WeatherUnicodeIconLib.GetBeaufortScaleIcon(Randomizer.Next(0, 12));

            DailyForecast.Add(NewForecastItem);
        }
    }
}

After that, the MockupViewModel has been added to the XAML code:
(Have a look to the last line of the UserControl header / tag)

<UserControl
x:Class="WeatherControl.WeatherControl"
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"
xmlns:vm="using:WeatherControl.ViewModel"
d:DataContext="{d:DesignInstance Type=vm:MockupModel, IsDesignTimeCreatable=True}">

<UserControl.Resources>
    <SolidColorBrush x:Key="FontColor">White</SolidColorBrush>
    <x:Double x:Key="MainInfoFontSize">90</x:Double>

    <Style TargetType="TextBlock">
        <Setter Property="FontFamily" Value="{StaticResource WeatherIcons}"/>
        <Setter Property="Foreground" Value="{StaticResource FontColor}"/>
        <Setter Property="FlowDirection" Value="LeftToRight"/>
        <Setter Property="FontSize" Value="30"/>
    </Style>
</UserControl.Resources>

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel
        HorizontalAlignment="Stretch"
        Padding="20">

        <StackPanel
            HorizontalAlignment="Stretch"
            Orientation="Horizontal"
            FlowDirection="RightToLeft">
            <TextBlock
                x:Name="SunSetRiseTime"
                Text="{Binding Path=CurrentData.SunRiseSetTime}"/>
            <TextBlock
                x:Name="SunSetRiseIcon"
                Text="{Binding Path=CurrentData.SunRiseSetIcon}"
                Margin="10,0,30,0"/>

            <TextBlock
                x:Name="WindDirectionIcon"
                Text="&#xf0b1;"
                RenderTransformOrigin="0.5 0.5">
                <TextBlock.RenderTransform>
                    <RotateTransform Angle="{Binding Path=CurrentData.WindDirectionDegrees}"/>
                </TextBlock.RenderTransform>
            </TextBlock>
            <TextBlock
                x:Name="WindBeaufortScaleIcon"
                Text="{Binding Path=CurrentData.WindSpeedIcon}"
                Margin="10,0,30,0"/>

            <TextBlock
                x:Name="PrecipitationIcon"
                Text="{Binding Path=CurrentData.PrecipitationIcon}"
                RenderTransformOrigin="0.5 0.5"/>
            <TextBlock
                x:Name="PrecipitationIconValue"
                Text="{Binding Path=CurrentData.PrecipitationValue}"
                Margin="10,0,20,0"/>
        </StackPanel>

        <StackPanel
            x:Name="MainInfos"
            HorizontalAlignment="Stretch"
            Orientation="Horizontal"
            FlowDirection="RightToLeft">
            <TextBlock
                x:Name="TemperatureUnitIcon"
                Text="{Binding Path=CurrentData.TemperatureUnitIcon}"
                FontSize="{StaticResource MainInfoFontSize}"
                Margin="0,0,10,0"/>
            <TextBlock
                Name="TemperatureValue"
                Text="{Binding Path=CurrentData.TemperatureValue}"
                FlowDirection="LeftToRight"
                FontSize="{StaticResource MainInfoFontSize}"
                Margin="0,0,40,0"/>
            <TextBlock
                x:Name="WeatherStatusIcon"
                Text="{Binding Path=CurrentData.WeatherStatusIcon}"
                FontSize="{StaticResource MainInfoFontSize}"/>
        </StackPanel>

        <TextBlock
                x:Name="WeatherDescription"
                Text="{Binding Path=CurrentData.WeatherStatusDescription}"
                TextAlignment="Right"
                Margin="0,0,0,20"/>

        <ListBox
            x:Name="DailyForecasts"
            HorizontalAlignment="Stretch"
            FlowDirection="RightToLeft"
            Background="Transparent"
            ItemsSource="{Binding Path=DailyForecast}">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Padding" Value="0"/>

                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel
                        x:Name="ForecastDay"
                        Orientation="Horizontal"
                        HorizontalAlignment="Stretch">
                        <TextBlock
                            x:Name="WindSpeed"
                            TextAlignment="Left"
                            Text="{Binding Path=WindSpeedIcon}"
                            Width="70"/>
                        <TextBlock
                            x:Name="Temperature"
                            TextAlignment="Right"
                            Text="{Binding Path=TemperatureValue}"
                            Width="60"/>
                        <TextBlock
                            x:Name="WeatherIcon"
                            TextAlignment="Center"
                            Text="{Binding Path=WeatherSatusIcon}"
                            Width="100"/>
                        <TextBlock
                            x:Name="DayName"
                            TextAlignment="Left"
                            Text="{Binding Path=Day}"
                            Width="70"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel>
</StackPanel>

You can also check out my project on github for more detailed code: https://github.com/Wasserwecken/SmartMirror

I hope you can help me here and thanks in advance!!!

解决方案

I hit the answer, by random.

  • After setting platform to "x86" (x64 does not work)
  • and enabling "project code" (Regarding to the answer from Mikael Koskinen)
  • Moving my "MockupModel" to the same namespace as the UserControl (Regarding to https://stackoverflow.com/a/17484110/3885480)
  • I set the configuration to "Release"

    --> It worked!

So i checked my project settings to figure out why, and compared the configurations
(Release / Debug)

  • After checking "Optimize Code" (For the Debug configuration)
  • and rebuilding (important)

  • --> there was no "Invalid Markup" anymore
  • --> and the MockupModel with his data showed up correctly!

This works for me in "VS 2015 Comminity Update3" and "VS 2017 RC"

这篇关于Visual Studio 不显示设计数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆