相关疑难解决方法(0)

Visual Studio 64位?

是否有任何64位Visual Studio?为什么不?

64-bit visual-studio

251
推荐指数
5
解决办法
20万
查看次数

在Window上设置设计时DataContext会产生编译错误吗?

我在WPF应用程序的主窗口下面有以下XAML,我正在尝试设置d:DataContext下面的设计时间,我可以成功地为我的各种UserControls做,但是当我尝试在窗口...

Error 1 The property 'DataContext' must be in the default namespace or in the element namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. Line 8 Position 9. C:\dev\bplus\PMT\src\UI\MainWindow.xaml 8 9 UI

<Window x:Class="BenchmarkPlus.PMT.UI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:UI="clr-namespace:BenchmarkPlus.PMT.UI"
    xmlns:Controls="clr-namespace:BenchmarkPlus.PMT.UI.Controls"
    d:DataContext="{d:DesignInstance Type=UI:MainViewModel, IsDesignTimeCreatable=True}"
    Title="MainWindow" Height="1000" Width="1600" Background="#FF7A7C82">

    <Grid>
        <!-- Content Here -->
    </grid>

</Window>
Run Code Online (Sandbox Code Playgroud)

wpf

201
推荐指数
2
解决办法
6万
查看次数

XAML是否有针对调试模式的条件编译器指令?

对于XAML中的样式我需要这样的东西:

<Application.Resources>

#if DEBUG
    <Style TargetType="{x:Type ToolTip}">
        <Setter Property="FontFamily" Value="Arial"/>
        <Setter Property="FlowDirection" Value="LeftToRight"/>
    </Style>
#else
    <Style TargetType="{x:Type ToolTip}">
        <Setter Property="FontFamily" Value="Tahoma"/>
        <Setter Property="FlowDirection" Value="RightToLeft"/>
    </Style>
#endif

</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

65
推荐指数
1
解决办法
2万
查看次数

如何在XAML编辑器中查看设计时数据绑定(它在运行时工作)?

我的数据绑定版本号如下所示:

<Window <!-- ... --> DataContext="{Binding RelativeSource={RelativeSource Self}}">
    <Grid>
        <TextBlock>
            Version is: 
            <Run Text="{Binding Version, Mode=OneWay}"></Run>
            and advancing...
        </TextBlock>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

它在运行期间正在运行.

如何在Visual Studio 2012的XAML编辑器中在设计时看到它?我只看到:

Version is: and advancing...
Run Code Online (Sandbox Code Playgroud)

代替:

Version is: 5.2.2 and advancing...
Run Code Online (Sandbox Code Playgroud)

编辑 - 我的解决方案:

下面的Jure的答案有效,但我最终使用了虚拟视图模型静态代码技术,这对我来说更好,因为数据是真实视图模型类型的模拟:

d:DataContext="{Binding Source={StaticResource DesignViewModel}}" ...
Run Code Online (Sandbox Code Playgroud)

data-binding wpf xaml design-time visual-studio

26
推荐指数
2
解决办法
3万
查看次数

在xaml中设计datatemplate的时间数据

这可能是一个愚蠢的问题,但是可以将一些示例数据定义为DataContext,以便在DesignView中查看我的DataTemplate吗?

目前,我总是要运行我的应用程序,看看我的更改是否正常.

例如,使用以下代码,DesignView只显示一个空列表框:

 <ListBox x:Name="standardLayoutListBox" ItemsSource="{Binding myListboxItems}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Label Grid.Column="0" Content="{Binding text1}" />
                <Label Grid.Column="1" Content="{Binding text2}" />
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

wpf xaml datatemplate designview

12
推荐指数
1
解决办法
1万
查看次数

如何设置在WPF设计模式下显示绑定属性的值?

我的绑定内容empty在UI设计模式中显示为字符串.我想为这些内容显示一些伪造的值,但我不知道如何.

如果你知道如何,请分享.谢谢!

data-binding wpf designmode

6
推荐指数
2
解决办法
4419
查看次数

在使用控件本身时,如何使用假数据设计时初始化XAML UserControl?

我有一个基本的WinRT XAML UserControl,它有一个依赖属性,如下所示.用户控件显然只在另一个Page或UserControl中使用时才构造设计时.当我使用用户控件本身在设计器中工作时,不会呈现文本"Hello world".在这种情况下,如何让设计器使用数据初始化用户控件?

XAML:

<UserControl
    x:Class="GTWin8.Ui.SimpleBinding"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:GTWin8.Ui"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    x:Name="ThisControl">

    <Grid Background="Black">
        <TextBlock Text="{Binding Path=Message, ElementName=ThisControl}" 
                   HorizontalAlignment="Left" Margin="10,10,0,0" 
                   TextWrapping="Wrap" VerticalAlignment="Top" Height="280" Width="380"/>
    </Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

代码隐藏:

public sealed partial class SimpleBinding : UserControl
{
    public static DependencyProperty MessageProperty = DependencyProperty.Register(
           "Message", typeof(String), typeof(SimpleBinding), new PropertyMetadata(null));

    public String Message
    {
        get { return (String)GetValue(MessageProperty); }
        set { SetValue(MessageProperty, value); }
    }

    public SimpleBinding()
    {
        this.InitializeComponent();
        Message = "Hello world";
    }
}
Run Code Online (Sandbox Code Playgroud)

xaml visual-studio windows-8 winrt-xaml

2
推荐指数
1
解决办法
2823
查看次数

如何在WPF中绑定其内容时设置默认Label值

我在XAML中定义了一个Label,如下所示:

<Label Content="{Binding Name}"></Label>
Run Code Online (Sandbox Code Playgroud)

问题是标签在XAML编辑器中是不可见的,我希望它在那里有一个默认值,以便编辑器准确地反映出在运行时显示的内容.

有没有办法在XAML中给它一个值,它将显示在编辑器中,但是然后在运行时使用绑定?

c# wpf xaml

2
推荐指数
1
解决办法
2666
查看次数