mogmo .NET

C#/XAML/VB6たまにC++についてメモ程度に書いていく。あくまで自分用。責任は取れません。

デザイン時のDataContextを設定する

mc:Ignorable名前空間

mc:Ignorable名前空間WPFで定義されているnamespaceです。
設計時にデザイナーが使用する情報ですが,コンパイル時は無視される情報となります。
WPFアプリを作成すると,自動でmc:Ignorable="d"が実装されていると思います。

<Window x:Class="***"
        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"
        xmlns:local="clr-namespace:***"
        mc:Ignorable="d"
        Title="***Window" Height="450" Width="800">

デザイナーのDataContextを設定する

mc:Ignorable名前空間でDataContextを設定します。

<Window x:Class="***"
        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"
        xmlns:local="clr-namespace:***"
        xmlns:viewmodel="clr-namespace:***.ViewModels"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance {x:Type viewmodel:***ViewModel}, IsDesignTimeCreatable=True}" 
        Title="***Window" Height="450" Width="800">