WPFxUPnP その2

まずは、デバイスとしてのAP作成。
VisualStudioでWPFアプリケーションを選んで、土台を作成。
こんな感じに作成してみました。

ボタンのON/OFFをライトのON/OFFに。
スライダーの値を、ライトの明るさにしてます。
後、ONの時は、円を黄色、OFFの時に灰色になるように、
ちょっと細工してみます。

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="UPnP Light" Height="200" Width="200" x:Name="Main"
        ResizeMode="NoResize">
    <StackPanel>
        <StackPanel Orientation="Horizontal">
            <ToggleButton x:Name="LightOn" Width="50" Content="ON"
                          IsChecked="{Binding Path=Light.ON, ElementName=Main}" />
            <Slider x:Name="Dimm" Margin="5"
                    Width="120" Value="{Binding Path=Light.Dimm, ElementName=Main}"
                    Ticks="0.1" Minimum="0.2" Maximum="1.0"
                    IsEnabled="{Binding Path=Light.ON, ElementName=Main}" />
        </StackPanel>
        <Ellipse Height="100" Width="100" Margin="15"
                 IsEnabled="{Binding Path=Light.ON, ElementName=Main}"
                 Opacity="{Binding Path=Light.Dimm, ElementName=Main}">
            <Ellipse.Style>
                <Style TargetType="{x:Type Ellipse}">
                    <Setter Property="Fill" Value="LightGray" />
                    <Style.Triggers>
                        <Trigger Property="IsEnabled" Value="True">
                            <Setter Property="Fill" Value="Yellow"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Ellipse.Style>
        </Ellipse>
    </StackPanel>
</Window>

using System.Windows;

public partial class MainWindow : Window
{
    public static readonly DependencyProperty LightProperty = DependencyProperty.Register("Light",
                                                                                            typeof(LightVM),
                                                                                            typeof(MainWindow),
                                                                                            new PropertyMetadata(new LightVM()));
    public LightVM Light
    {
        get { return (LightVM)this.GetValue(LightProperty); }
        set { this.SetValue(LightProperty, value); }
    }
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
    }
}

using System.ComponentModel;

public class Light
{
    bool _On = true;
    public bool On
    {
        get {return _On; }
        set { _On = value; }
    }
 
    double _Dimm = 1.0;
    public double Dimm
    {
        get { return _Dimm; }
        set { _Dimm = value; }
    }
}
 
public class LightVM : INotifyPropertyChanged
{
    Light Light = new Light();
 
    public bool ON
    {
        get { return Light.On; }
        set
        {
            Light.On = value;
            ChangeNotify("ON");
        }
    }
 
    public double Dimm
    {
        get { return Light.Dimm; }
        set
        {
            Light.Dimm = value;
            ChangeNotify("Dimm");
        }
    }
 
    protected void ChangeNotify(string name)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
}