LoginSignup
6

More than 5 years have passed since last update.

WPFでWindowとかUserControlエレメントでStaticResourceを呼ぶとエラーになった

Last updated at Posted at 2015-08-04

なんかエラー出てはまったので

こんなViewModelがあるとして

    public class MainVM : BindableBase
    {
        private string _Title;
        public string Titile
        {
            get { return _Title; }
            set { SetProperty(ref _Title, value); }
        }

        private bool _IsVisible;
        public bool IsVisible
        {
            get { return _IsVisible; }
            set { SetProperty(ref _IsVisible, value); }
        }

    }

こんなXamlだとする。

<Window x:Class="WpfApplication1.MainWindow"
        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:WpfApplication1"
        mc:Ignorable="d"
        Height="350" Width="525" 
        Title="{Binding Title}" 
        Visibility="{Binding Path=IsVisible,Converter={StaticResource bvConv}}">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="bvConv" />
    </Window.Resources>
    <Grid>

    </Grid>
</Window>

エラー

ぎゃ~~( ;∀;)


<Window x:Class="WpfApplication1.MainWindow"
        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:WpfApplication1"
        mc:Ignorable="d"
        Height="350" Width="525" 
        Title="{Binding Title}">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="bvConv" />
    </Window.Resources>
    <Window.Style>
        <Style TargetType="{x:Type Window}">
            <Setter Property="Visibility" Value="{Binding Path=IsVisible,Converter={StaticResource bvConv}}" />
        </Style>
    </Window.Style>
    <Grid>

    </Grid>
</Window>

でオッケー(^^)/

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6