Quantcast
Channel: Windows Presentation Foundation ( WPF ) フォーラム
Viewing all 711 articles
Browse latest View live

CalenderコントロールおよびDatePickerコントロール内Calenderコントロールの和暦表示に関して

$
0
0

CalenderコントロールおよびDatePickerコントロール内Calenderコントロールの年表示を和暦にしたいと思っています。
以下のようなコードでカルチャーを変更してあげることで、カレンダーの初期表示では一見和暦に対応したように思えたのですが

CultureInfo culture = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
Thread.CurrentThread.CurrentCulture = culture;

Calenderコントロールは上部の年表示部分をマウスでクリックすると、月選択画面、年選択画面へと遷移しますが、残念ながらそれらの画面の年表示は和暦になっていませんでした。

月選択画面、年選択画面も含め、すべての年表示を和暦にすることはできないでしょうか?

対象環境
OS
Windows 8.1
Microsoft Windows [Version 6.3.9600]

開発環境
Microsoft Visual Studio Premium 2012
Version 11.0.61030.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

プロジェクトの対象フレームワーク
.NET Framework 4.5



独自のShapeの作成方法

$
0
0

[質問]
MyPolylineを修正して意図通り描画できるようにしたい。

[目標]
double.NaNを無視するMyPolylineを作成する。
この例題を通じて独自Shapeを作成する方法を習得する。

[現状]
PolylineボタンをClickすると、標準のPolylineは折れ線が描画しますが、
MyPolylineボタンをClickしても、MyPolylineは何も描画しません。

よろしくお願いします。

[以下、ソースコード]

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:local="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525"><Window.Resources><local:ObservableToPointCollection x:Key="ObservableToPointCollection" /></Window.Resources><Grid><Button Content="Polyline" HorizontalAlignment="Left" Margin="32,32,0,0" VerticalAlignment="Top" Width="75" Click="PolylineButton_Click"/><Button Content="MyPolyline" HorizontalAlignment="Left" Margin="132,32,0,0" VerticalAlignment="Top" Width="75" Click="MyPolylineButton_Click"/><Polyline Points="{Binding Items,Mode=OneWay,Converter={StaticResource ObservableToPointCollection}}" Stroke="Black" /><local:MyPolyline Points="{Binding Items,Mode=OneWay,Converter={StaticResource ObservableToPointCollection}}" Stroke="Red" /></Grid></Window>

C#

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            _myData = new MyData();
            DataContext = _myData;
        }

        private MyData _myData;

        private void PolylineButton_Click(object sender, RoutedEventArgs e)
        {
            ObservableCollection<Point> tempItems = new ObservableCollection<Point>();
            tempItems.Add(new Point(0, 0));
            tempItems.Add(new Point(0, 100));
            tempItems.Add(new Point(100, 100));
            tempItems.Add(new Point(100, 0));
            _myData.Items = tempItems;
        }

        private void MyPolylineButton_Click(object sender, RoutedEventArgs e)
        {

        }
    }

    public sealed class MyData : INotifyPropertyChanged
    {

        public ObservableCollection<Point> Items
        {
            get { return _items; }
            set
            {
                _items = value;
                OnPropertyChanged("Items");
            }
        }

        private ObservableCollection<Point> _items;

        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

    /// <summary>
    /// double.NaNを無視するPolyline
    /// </summary>
    public sealed class MyPolyline : Shape
    {
        #region 依存プロパティ

        /// <summary>
        /// 折れ線を構成する点
        /// </summary>
        public static readonly DependencyProperty PointsProperty = DependencyProperty.Register("Points", typeof(PointCollection), typeof(MyPolyline));

        /// <summary>
        /// 折れ線を構成する点
        /// </summary>
        public PointCollection Points
        {
            get
            {
                return (PointCollection)base.GetValue(PointsProperty);
            }
            set
            {
                base.SetValue(PointsProperty, value);
            }
        }


        #endregion

        /// <summary>
        /// 折れ線の形状(double.NaNを無視)
        /// </summary>
        protected override Geometry DefiningGeometry
        {
            get
            {
                PathGeometry path = new PathGeometry();
                if (Points != null)
                {
                    int count = Points.Count;
                    if (count >= 2)
                    {
                        for (int index = 0; index < count - 1; index++)
                        {
                            Point p1 = Points[index];
                            Point p2 = Points[index + 1];
                            // double.NaNが含まれる場合は無視します。
                            if ((!double.IsNaN(p1.X)) && (!double.IsNaN(p1.Y)) && (!double.IsNaN(p2.X)) && (!double.IsNaN(p2.Y)))
                            {
                                LineGeometry line = new LineGeometry(p1, p2);
                                path.AddGeometry(line);
                            }
                        }
                    }
                }
                return path;
            }
        }

    }

    public sealed class ObservableToPointCollection : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return null;
            if (value.GetType() != typeof(ObservableCollection<Point>)) return null;
            if (targetType != typeof(PointCollection)) return null;
            ObservableCollection<Point> items = value as ObservableCollection<Point>;
            PointCollection points = new PointCollection();
            foreach (Point item in items)
            {
                points.Add(item);
            }
            return points;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
    }
}


C#開発者

WebcamControlがWindows8.0で動作しない?

$
0
0

お世話になります。

WPFでカメラを扱うアプリを作成しようと思い、コードプロジェクトのサンプル

http://www.codeproject.com/Articles/285964/WPF-Webcam-Control

を見つけアプリを作成途中です。試したところWindows7では動作しますが、Windows8.0では、動作しません。

「WebcamControl.Webcam のタイプ初期化子が例外をスローしました」

と言ってきます。

これは、どうしたら使用できますか?また、仕様?で動作しないのでしょうか?

よろしくお願いします。 Windows7(開発) VS2010 WPF C# Winアプリ

XAMLデザイナ上での「"TYPE"のインスタンスを作成できません。」エラーに関して

$
0
0

ユーザーコントロールを貼り付けているデザイナで、XAMLのソースを編集したのちにデバッグの開始を実行するとタイトルのようなエラーが発生してしまいます。このエラーを発生させないようにするにはどうしたらよいでしょうか?過去にも類似した質問があり、プロパティの登録時に間違った方で初期化を行っていないかを確認しましたが、そこは正しいようです。

以下のようなプログラムです。

MainWindow.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:local="clr-namespace:WpfApplication1"
        Title="MainWindow" Height="350" Width="525"><Grid><local:UserControl1 MyProperty="1"></local:UserControl1></Grid></Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

UserControl1.xaml

<UserControl x:Class="WpfApplication1.UserControl1"
             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"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"><Grid></Grid></UserControl>

UserControl1.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        public static int GetMyProperty(DependencyObject obj)
        {
            return (int)obj.GetValue(MyPropertyProperty);
        }

        public static void SetMyProperty(DependencyObject obj, int value)
        {
            obj.SetValue(MyPropertyProperty, value);
        }

        public int MyProperty
        {
            get { return GetMyProperty(this); }
            set { SetMyProperty(this, value); }
        }

        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.RegisterAttached("MyProperty", typeof(int), typeof(UserControl1), new FrameworkPropertyMetadata(0, new PropertyChangedCallback(OnMyPropertyChanged)));

        private static void OnMyPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
        }
    }
}

MainWindow.xamlをデザイナで開いた直後は問題なく表示されています。

作成された実行モジュールでの実行時には発生していません。

申し訳ありません、環境を追記いたします

OS
Windows 8.1
Microsoft Windows [Version 6.3.9600]

開発環境
Microsoft Visual Studio Premium 2012
Version 11.0.61030.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

プロジェクトの対象フレームワーク
.NET Framework 4.5

WPF CANVAS上のshapeをマウスで引いた自由曲線の範囲から検索したい

$
0
0

WPFのCANVASに複数のshape(TextBlockやLineなど)を配置しています。
CANVAS上をマウスでドラッグした範囲内にあるshapeを取得したいと思っています。

以下の方法でドラッグした軌跡からPathGeometryを生成しHITTESTしているのですが全くヒットしません。

=================
マウスドラッグ時にPathFigureを生成しています。

Private Sub myCanvas_MouseDown(....
 figu.StartPoint = point
End Sub
Private Sub myCanvas_MouseMove(....
 figu.Segments.Add(New LineSegment(point, True))
End Sub

ドラッグ完了時にCANVAS内のshape1つ1つにHitTestをしているのですが、
全くヒットしません。
Private Sub myCanvas_MouseUp(....
 myPathGeometry.Figures.Add(figu)
 ....
 VisualTreeHelper.HitTest(wktxtblock, Nothing, New HitTestResultCallback(AddressOf MyHitTestResultCallback), New GeometryHitTestParameters(myPathGeometry))
....

=================

他の方法でも良いのですが、任意の自由曲線内にあるshapeを検索するには
どうしたらよいでしょうか?
よろしくお願いいたします。

ListViewに要素を追加した時に、表示内容が動かないようにしたい

$
0
0

図の左のように、スクロールの位置が先頭に無い時、ListViewに対してItems.Insert(0, hoge); のようにして要素を追加したとき、図の右のようにスクロールが移動することによってListViewの表示内容が動かないようにしたいです。

現在のInsert(0,hoge);の挙動としては、スクロール位置は固定で、表示内容は下に流れていくというものになっています。

なお、ListViewと類似のコントロールであればListViewに対してこだわりはありません。

お力添えよろしくお願いします。

IEnumerableな依存関係プロパティに対してデータバインドできません

$
0
0

開発環境:VS2013 Pro
.Net Framework 4.5


カスタムコントロールに自分で IEnumerable<double> の依存関係プロパティを追加し、
これを View の XAML でデータバインドして、
ViewModel からデータを変更することを考えています。

ところが、ViewModel からデータを変更しても、
その変更が反映されず、
カスタムコントロールのプロパティ値変更イベントハンドラも反応しませんでした。

同様のコードで double の依存関係プロパティで動作確認すると
こちらは問題なくデータバインドの機能が働きました。

IEnumerable<T> に対してデータバインドできる
依存関係プロパティの作成方法を教えて下さい。

動作確認に用いたプロジェクトの構造は下図のようになります。
デフォルトの WPF アプリケーションプロジェクトを作成し、
WPF カスタムコントロールをひとつと、
MainViewModel クラスを追加しただけのプロジェクトです。
ソリューションツリー

以下動作確認用に編集した部分のコードです。


カスタムコントロールのコード

namespace Test
{
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;

    public class CustomControl1 : Control
    {
        public static readonly DependencyProperty ValuesProperty = DependencyProperty.Register("Values", typeof(IEnumerable<double>), typeof(CustomControl1), new FrameworkPropertyMetadata(new double[] { 1.0, 2.0, 3.0 }, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (s, e) => { (s as CustomControl1).OnValuesChanged(); }));

        public IEnumerable<double> Values
        {
            get { return (IEnumerable<double>)GetValue(ValuesProperty); }
            set { SetValue(ValuesProperty, value); }
        }

        private void OnValuesChanged()
        {
            string valuesString = "NULL";
            if (Values != null)
            {
                valuesString = "[ ";
                foreach (var value in Values)
                {
                    valuesString += value.ToString() + " ";
                }
                valuesString += "]";
            }
            System.Diagnostics.Debug.WriteLine("ValuesProperty changed. " + valuesString);
        }

        public CustomControl1()
        {
            Values = new double[] { 10.0, 20.0, 30.0 };
        }

        static CustomControl1()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
        }
    }
}

Generic.xaml のコード

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Test"><Style TargetType="{x:Type local:CustomControl1}"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type local:CustomControl1}"><Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"><ItemsControl ItemsSource="{Binding Values, RelativeSource={RelativeSource TemplatedParent}}"><ItemsControl.ItemTemplate><DataTemplate><TextBlock Text="{Binding}" /></DataTemplate></ItemsControl.ItemTemplate></ItemsControl></Border></ControlTemplate></Setter.Value></Setter></Style></ResourceDictionary>

MainWindow.xaml のコード
<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Test"
        Title="MainWindow" Height="350" Width="525"><Window.DataContext><local:MainViewModel /></Window.DataContext><Grid><StackPanel><Button Content="click me." Command="{Binding TestCommand}" /><local:CustomControl1 /></StackPanel></Grid></Window>

MainViewModel のコード
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Input;

    public class MainViewModel : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged のメンバ
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged(string propertyName)
        {
            var h = PropertyChanged;
            if (h != null)
                h(this, new PropertyChangedEventArgs(propertyName));
        }

        protected virtual bool SetProperty<T>(ref T target, T value, string propertyName = null)
        {
            if (target == null)
                return false;
            if (Equals(target, value))
                return false;
            target = value;
            RaisePropertyChanged(propertyName);
            return true;
        }
        #endregion INotifyPropertyChanged のメンバ

        private IEnumerable<double> sampleValues1;
        public IEnumerable<double> SampleValues1
        {
            get { return sampleValues1; }
            set { SetProperty(ref sampleValues1, value); }
        }

        public MainViewModel()
        {
            SampleValues1 = new double[] { 100.0, 200.0, 300.0 };
        }

        private DelegateCommand testCommand;
        public DelegateCommand TestCommand
        {
            get
            {
                if (testCommand == null)
                    testCommand = new DelegateCommand(_ =>
                    {
                        SampleValues1 = new double[] { 1000.0, 2000.0, 3000.0 };
                        System.Diagnostics.Debug.WriteLine("SampleValues changed to [ 1000.0 2000.0 3000.0 ].");
                    });
                return testCommand;
            }
        }
    }

    public class DelegateCommand : ICommand
    {
        private Action<object> _execute;
        private Func<object, bool> _canExecute;

        public DelegateCommand(Action<object> execute)
            : this(execute, null)
        {
        }

        public DelegateCommand(Action<object> execute, Func<object, bool> canExecute)
        {
            _execute = execute;
            _canExecute = canExecute;
        }

        #region ICommand のメンバ
        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }

        public event System.EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested+= value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            if (_execute != null)
                _execute(parameter);
        }
        #endregion ICommand のメンバ
    }

}



階層構造を持つコントロールに追加した依存関係プロパティにデータバインドできない

$
0
0

開発環境:VS2013 Pro
.NET Framework 4.5

カスタムコントロールに double と IEnumerable<double> の
依存関係プロパティを追加しました。
さらに IEnumerable の依存関係プロパティを追加し、
自身の配列を指定することで階層構造を持つカスタムコントロールとなるようにしました。

このような状況で、
親となるカスタムコントロールに対するプロパティは
通常通りにデータバインドできました。
しかし、
その下の子供となるカスタムコントロールに対する
double あるいは IEnumerable<double> の依存関係プロパティに対して
データバインドしようとしましたが、
プロパティ変更通知が機能しませんでした。

以下に動作確認用のコードを掲載します。
もしかして XAML の中で <x:Array ・・・> を使用しているのがいけないような気がしていますが、
他のコードで同じことを実現する方法が思い付きませんでした。

どのようにすれば子供のカスタムコントロールの
プロパティ変更通知が機能するのでしょうか。


動作確認に用いたプロジェクトの構造は下図のようになります。
デフォルトの WPF アプリケーションプロジェクトを作成し、
WPF カスタムコントロールをひとつと、
MainViewModel.cs を追加しただけのプロジェクトです。
テスト用ソリューションツリー構造

以下動作確認用に編集した部分のコードです。

カスタムコントロールのコード

namespace Test
{
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;

    public class CustomControl1 : Control
    {
        #region Items プロパティ
        public static readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(IEnumerable), typeof(CustomControl1), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (s, e) => { (s as CustomControl1).OnItemsChanged(); }));
        public IEnumerable Items
        {
            get { return (IEnumerable)GetValue(ItemsProperty); }
            set { SetValue(ItemsProperty, value); }
        }

        private void OnItemsChanged()
        {
            var str = "NULL";
            if (Items != null)
            {
                str = "[ ";
                foreach (var obj in Items)
                {
                    var item = obj as Control;
                    str += item != null ? item.Name + " " : "NULL ";
                }
                str += "]";
            }
            System.Diagnostics.Debug.WriteLine("Items changed. " + str);
        }
        #endregion Items プロパティ

        #region Values プロパティ
        public static readonly DependencyProperty ValuesProperty = DependencyProperty.Register("Values", typeof(IEnumerable<double>), typeof(CustomControl1), new FrameworkPropertyMetadata(new double[] { 1.0, 2.0, 3.0 }, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (s, e) => { (s as CustomControl1).OnValuesChanged(); }));
        public IEnumerable<double> Values
        {
            get { return (IEnumerable<double>)GetValue(ValuesProperty); }
            set { SetValue(ValuesProperty, value); }
        }

        private void OnValuesChanged()
        {
            string valuesString = "NULL";
            if (Values != null)
            {
                valuesString = "[ ";
                foreach (var value in Values)
                {
                    valuesString += value.ToString() + " ";
                }
                valuesString += "]";
            }
            System.Diagnostics.Debug.WriteLine("[" + Name + "] ValuesProperty changed. " + valuesString);
        }
        #endregion Values プロパティ

        #region Test プロパティ
        public static readonly DependencyProperty TestProperty = DependencyProperty.Register("Test", typeof(double), typeof(CustomControl1), new FrameworkPropertyMetadata(default(double), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (s, e) => { (s as CustomControl1).OnTestChanged(); }));
        public double Test
        {
            get { return (double)GetValue(TestProperty); }
            set { SetValue(TestProperty, value); }
        }

        private void OnTestChanged()
        {
            System.Diagnostics.Debug.WriteLine("[" + Name + "] Test changed to " + Test.ToString());
        }
        #endregion Test プロパティ

        #region コンストラクタ
        public CustomControl1()
        {
            Values = new double[] { 10.0, 20.0, 30.0 };
        }

        static CustomControl1()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
        }
        #endregion コンストラクタ
    }
}

MainWindow.xaml のコード
<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Test"
        Title="MainWindow" Height="350" Width="525"><Window.DataContext><local:MainViewModel /></Window.DataContext><Grid><StackPanel><Button Content="click me." Command="{Binding TestCommand}" /><local:CustomControl1 x:Name="parent" Values="{Binding ParentValues}" Test="{Binding ParentTestValue}"><local:CustomControl1.Items><x:Array Type="{x:Type local:CustomControl1}"><local:CustomControl1 x:Name="child01" Values="{Binding SampleValues1}" Test="{Binding TestValue1}" /><local:CustomControl1 x:Name="child02" Values="{Binding SampleValues2}" Test="{Binding TestValue2}" /><local:CustomControl1 x:Name="child03" Values="{Binding SampleValues3}" Test="{Binding TestValue3}" /></x:Array></local:CustomControl1.Items></local:CustomControl1></StackPanel></Grid></Window>

MainViewModel のコード
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Input;

    public class MainViewModel : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged のメンバ
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void RaisePropertyChanged(string propertyName)
        {
            var h = PropertyChanged;
            if (h != null)
                h(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion INotifyPropertyChanged のメンバ

        private IEnumerable<double> parentValues;
        public IEnumerable<double> ParentValues
        {
            get { return parentValues; }
            set
            {
                parentValues = value;
                RaisePropertyChanged("ParentValues");
            }
        }

        private IEnumerable<double> sampleValues1;
        public IEnumerable<double> SampleValues1
        {
            get { return sampleValues1; }
            set
            {
                sampleValues1 = value;
                RaisePropertyChanged("SampleValues1");
            }
        }

        private IEnumerable<double> sampleValues2;
        public IEnumerable<double> SampleValues2
        {
            get { return sampleValues2; }
            set
            {
                sampleValues2 = value;
                RaisePropertyChanged("SampleValues2");
            }
        }

        private IEnumerable<double> sampleValues3;
        public IEnumerable<double> SampleValues3
        {
            get { return sampleValues3; }
            set
            {
                sampleValues3 = value;
                RaisePropertyChanged("SampleValues3");
            }
        }

        private double parentTestValue;
        public double ParentTestValue
        {
            get { return parentTestValue; }
            set
            {
                parentTestValue = value;
                RaisePropertyChanged("ParentTestValue");
            }
        }

        private double testValue1;
        public double TestValue1
        {
            get { return testValue1; }
            set
            {
                testValue1 = value;
                RaisePropertyChanged("TestValue1");
            }
        }

        private double testValue2;
        public double TestValue2
        {
            get { return testValue2; }
            set
            {
                testValue2 = value;
                RaisePropertyChanged("TestValue2");
            }
        }

        private double testValue3;
        public double TestValue3
        {
            get { return testValue3; }
            set
            {
                testValue3 = value;
                RaisePropertyChanged("TestValue3");
            }
        }

        public MainViewModel()
        {
            ParentValues = new double[] { 111.0, 222.0, 333.0 };
            SampleValues1 = new double[] { 100.0, 200.0, 300.0 };
            SampleValues2 = new double[] { 400.0, 500.0, 600.0 };
            SampleValues3 = new double[] { 700.0, 800.0, 900.0 };

            ParentTestValue = 111.0;
            TestValue1 = 100.0;
            TestValue2 = 200.0;
            TestValue3 = 300.0;
        }

        private DelegateCommand testCommand;
        public DelegateCommand TestCommand
        {
            get
            {
                if (testCommand == null)
                    testCommand = new DelegateCommand(_ =>
                    {
                        System.Diagnostics.Debug.WriteLine("TestCommand executed.");

                        ParentValues = new double[] { 1111.0, 2222.0, 3333.0 };
                        SampleValues1 = new double[] { 1000.0, 2000.0, 3000.0 };
                        SampleValues2 = new double[] { 4000.0, 5000.0, 6000.0 };
                        SampleValues3 = new double[] { 7000.0, 8000.0, 9000.0 };

                        ParentTestValue = 1111.0;
                        TestValue1 = 1000.0;
                        TestValue2 = 2000.0;
                        TestValue3 = 3000.0;
                    });
                return testCommand;
            }
        }
    }

    public class DelegateCommand : ICommand
    {
        private Action<object> _execute;
        private Func<object, bool> _canExecute;

        public DelegateCommand(Action<object> execute)
            : this(execute, null)
        {
        }

        public DelegateCommand(Action<object> execute, Func<object, bool> canExecute)
        {
            _execute = execute;
            _canExecute = canExecute;
        }

        #region ICommand のメンバ
        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }

        public event System.EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested+= value; }
            remove { CommandManager.RequerySuggested -= value; }
        }

        public void Execute(object parameter)
        {
            if (_execute != null)
                _execute(parameter);
        }
        #endregion ICommand のメンバ
    }

}



余談になりますが、
TabControl なんかでは <x:Array /> を使用せずに
次のように記述できますよね。
これって ItemsControl を使わずに実現するには
どうればいいんでしょうか。
これができれば解決できる気もするんですが…。

<TabControl><TabItem Header="1" /><TabItem Header="2" /><TabItem Header="3" /></TabControl>


CommandParameter に複数の要素を指定する方法について

$
0
0

WPF でアプリケーションを作っています。

Window に TextBox1、TextBox2、Button を配置し、Button をクリックすると、Button の CommandParameter として TextBox1、TextBox2 の Text プロパティを指定したいと考えています。

TextBox1 だけなら、以下の記述でできます。

        <Button Content="Button" Height="28" HorizontalAlignment="Left" Margin="542,338,0,0"
                Name="button3" VerticalAlignment="Top" Width="153"
                Command="{Binding Source={StaticResource myCommand}}"
               CommandParameter="{Binding ElementName=textBox1, Path=Text}">
        </Button>

ただ、2 つ以上の要素を指定したい場合の記述が分かりません。ご教授いただけないでしょうか。よろしくお願いいたします。

PC付属のカメラの撮影・保存の解像度って変更できますか?

$
0
0

Windows 8 のタブレットPCで以前カメラ使用の件でお世話になりました。

この件、まだ少し引きずっています。

http://www.codeproject.com/Articles/330177/Yet-another-Web-Camera-control

のサイトのサンプルを使用する限り、私の周りにあるカメラ付きパソコンのすべてで動作しました。

そこでこのサンプルで現在、作業を進めていますが、解像度の設定がわかりません。

動画をキャプチャーする時にも、640×480とか、780×1024など他のDirectShowなど見るとできるようですが、

このサンプルの場合、どこを調べればよいかわかりません。

分かる方がお見えでしたら教えてください。

知りたいのは、動画のキャプチャーの解像度とそれを保存するときのBitmap(JPG)のサイズ。

このサンプルのままだと保存されるビットマップ画像は、640×480でファイル容量が20、30KBととても小さいです。

        internal Bitmap GetCurrentImage()
        {
            IntPtr dibPtr;
            ThrowExceptionForResult(_getCurrentImage(out dibPtr), "Failed to get the current image.");

            try
            {
                BITMAPINFOHEADER biHeader = (BITMAPINFOHEADER)Marshal.PtrToStructure(dibPtr, typeof(BITMAPINFOHEADER));
                Int32 stride = biHeader.biWidth * (biHeader.biBitCount / 8);

                PixelFormat pixelFormat = PixelFormat.Undefined;
                switch (biHeader.biBitCount)
                {
                    case 1:
                        pixelFormat = PixelFormat.Format1bppIndexed;
                        break;
                    case 4:
                        pixelFormat = PixelFormat.Format4bppIndexed;
                        break;

上記は、その一部のコードの抜粋ですが、4行目の_getCurrentImage(out dibPtr)でイメージのポインタを取得しているようなので、元画像がこのサイズ?と推測しますが、これは大きくできないのでしょうか?

それとも付属のカメラの性能?に起因するので不可能ですか?

開発環境Windows7 VS2010 C# WPF Winアプリ

Adobe Illustratorから生成されたXAMLのボタン化とボタンの状態ごとのデザインの変更

$
0
0

.NET Framework 4.0にてWPFを使用しています。
WPFを使用するのは今回が初めてで、現在勉強中です。
開発環境はVisual Studio 2013 Professionalです。

デザイン部分を他の方に発注したところ、WPFを使うということで各種パーツをXAMLで納品していただくことになりました。
納品サンプルを見せていただいたところ、Adobe Illustratorで作成したベクター画像を下記のプラグインを用いてXAMLに変換しておられるようでした。

http://www.mikeswanson.com/XAMLExport/

頂いたサンプルは下記のような構造になっていました。

<Viewbox Width="XXX" Height="XXX"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Canvas Width="XXX" Height="XXX">
    <Canvas>
      <Path Fill="#XXX" Data="XXX"/>
      <Path Fill="#XXX" Data="XXX"/>
    </Canvas>
  </Canvas>
</Viewbox>

このようなボタン用のXAMLファイルが
・通常状態
・マウスがボタン上にあるときのホバー状態
・押下状態
とわけて存在しています。

これらXAMLファイルに文字を表示しつつそれぞれの状態で切り替わるようなボタンコントロールとするにはどのような方法があるでしょうか?

下記のようなやり方を考えているのですが、これで実現できるでしょうか?
1.上記XAMLにTextBlockを追加して文字を追加
2.XAMLをカスタムコントロール化
3.カスタムコントロール化したボタンをアプリケーション上のXAMLに配置
4.コントロールテンプレートを記述してボタン状態ごとに切り替えるよう修正

また、特に2→3→4のやり方について詳しく記述されている記事や本、サンプルなどはないでしょうか?
あるいはこれ以外のよい方法はないでしょうか?

複雑な質問となってしまい申し訳ございません。

回答よろしくお願いします。


Windowを利用してRibbonコントロールを使用する方法

$
0
0

Ribbonについて質問です。
まず、通常のツールメニューではなく、Ribbonのツールメニューを利用したいと考えています。

問題は、最初にRibbonWindowを使うと以下のような問題が発生していまいました。
RibbonWindowの縁が非常に小さくなってしまい、デザインが非常に崩れてしまいます。

http://days-of-programming.blogspot.jp/2014/06/ui.html
https://connect.microsoft.com/VisualStudio/feedback/details/775972/wpf-ribbon-window-the-border-is-too-thin

同記事を記述された方は解決したともありますが、RibbonWindowは不安があるので通常のWindowにRibbonのメニューを追加しようと考えています。
(解決案はWindows8でみるとGlassFrameThicknessの大きさに差があるのか黒い縁が見えたりしていました)

http://days-of-programming.blogspot.jp/2014/07/windowchromewpfribbonwindow_12.html


ただ、通常のWindow上でRibbonを利用すると今度は以下のように出力ウィンドウにエラー表示が発生します。
なにかの参照のためRibbonWindowを期待しているようなのですが、不必要なので解除したいです。

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Ribbon.RibbonWindow', AncestorLevel='1''. BindingExpression:Path=WindowState; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.Ribbon.RibbonWindow', AncestorLevel='1''. BindingExpression:Path=IsActive; DataItem=null; target element is 'Ribbon' (Name=''); target property is 'NoTarget' (type 'Object')



通常のWindow上でRibbonを利用するとして、
この「System.Windows.Data Error: 4」を解決するには、どのようにすればよいでしょうか。


また、RibbonWindow、Windowどちらの場合でもRibbonメニュー上でマウスを操作していると、出力ウィンドウに以下のエラー表示が発生します。

System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='55671433'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode='55671433'; TargetElement.Type='System.Windows.Media.Animation.Storyboard'
System.Windows.Media.Animation Warning: 6 : Unable to perform action because the specified Storyboard was never applied to this object for interactive control.; Action='Stop'; Storyboard='System.Windows.Media.Animation.Storyboard'; Storyboard.HashCode='31929589'; Storyboard.Type='System.Windows.Media.Animation.Storyboard'; TargetElement='System.Windows.Media.Animation.Storyboard'; TargetElement.HashCode='31929589'; TargetElement.Type='System.Windows.Media.Animation.Storyboard'

この解除方法についても、なにか情報や解決策があれば教えてほしいです。
以上、分かる方いましたら、よろしくお願いします。

WindowからMouseが離れている間にもイベントをキャッチする方法。

$
0
0

お世話になっております。

WPFで開発をする際に、ComboboxにFocusが当たっている場合で、ApplicationのWindow外にマウスがあるでもMouseScrollEventをキャッチし、Comboboxの値を変える方法を探しております。

WindowFormsでは実現可能だったと思うのですが、WPFでMouseがWindow境界外にある場合のイベントキャッチ方法がわかりません。

ご存じの方がいらっしゃいましたらご教示頂けますようお願い申しあげます。


繰り返し出現するXAML構造の再利用方法ついて

$
0
0

.NET Framework 4.0にてWPFを使用しています。
WPFを使用するのは今回が初めてで、現在勉強中です。
開発環境はVisual Studio 2013 Professionalです。

下記のような一式のコントロールを様々なところで使いまわします。

<Grid><Grid.ColumnDefinitions><ColumnDefinition Width="1*"/><ColumnDefinition Width="5*"/><ColumnDefinition Width="1*"/></Grid.ColumnDefinitions><TextBlock Grid.Column="0" VerticalAlignment="Center">
            Name</TextBlock><TextBox Grid.Column="1" TextAlignment="Right" VerticalAlignment="Center">
            Value</TextBox><TextBlock Grid.Column="2" VerticalAlignment="Center">
            Unit</TextBlock>
  </Grid>

※ただし、Name, Value, Unitは配置場所によって中身が異なります。

上記のような一式のXAML構造を様々なところで効率的に使いまわすにはどのような方法が適しているのでしょうか?

ユーザーコントロールにひとまとめにして……とWindows Formのようなやり方を考えているのですが、その場合Name, Value, UnitをXAML上に記述する方法がわかりません。

XAMLのパーツを効率的使いまわす(かつ、部分的なプロパティを配置場所ごとに設定可能にする)方法がありましたらご教授お願いします。

XPSファイルの編集

$
0
0
すでに作成済みにXPSファイルがあります。
このXPSファイルを開いて,ページごとに文字列や画像を追加したいのですが,どのような手段が考えられますでしょうか?
FixedPageが取得できれば,オブジェクトを追加できるような気もするのですが,XPSDocumentからFixedPageを取得して上書き(または別名保存)する方法が全然思いつきません。
どなたか,アドバイスいただけますと幸いです。

Blend for Visual Studio 2013でブラシのエディターのカラーパレットを設定すると『プロパティ値が無効です。』というエラーが出る

$
0
0

Blend for Visual Studio 2013においてWPFアプリケーションのプロジェクトを作成しました。

MainWindow.xamlにButtonコントロールを追加して、

今後ボタンはカラーを統一した設定をしたいと考えたので

リソースディクショナリを新規に作成した上で、コントロールテンプレートを作成しました。

コントロールテンプレートのgridを選択してブラシ-エディターのカラーパレットをクリックしたところ、

『プロパティ値が無効です。』

というエラーメッセージが発生しました。

ただし、ビルドが通らないことは無く、アプリ自体では設定した色の通り動作しているように見えました。

この問題はデザイナー上のみにおける問題なのでしょうか?

そもそもとして私の操作が誤っているのでしょうか?

情報をお持ちの方、よろしくお願いいたします。


WPFのComboBoxにsqlの結果をバインド

$
0
0

C#2013を用いてデータベースシステムのWPFアプリを作成しています。

ComboBoxにSQL結果を入力したいため下記のようなコードを実行しています。

返ってきた結果をレコードの最初から最後まで順番にComboBoxにAddしています。

while (reader.Read())
{
this.comboBox.Items.Add((String)reader.GetValue(0) );

}

しかし、この方法ではAccessと比較しても時間がかかってしまいます。

SQLの結果をcomboBoxのitemsSourceにバインドすれば速度の向上が期待できると思い、調べたのですが、

具体的な方法がわかりません。

お分かりになられる方がいらっしゃいましたらご教授よろしくお願い致します。

ObservableCollectionをバインドしたDataGridの更新

$
0
0

現在C#2013のWPFでデータを取り扱うアプリを作成しています。

データベースから取得したデータをObservableCollectionに追加後,DataGridにBindしています。

Form上でデータベースにデータを追加したら、DataGridにも反映させたいのですが、方法がどうしても分かりません。

OBservableCollectionにデータを追加する部分は以下のようになります。

class view_ProgramList 


    {

        public ObservableCollection<View_Program> vProgram { get; set; }

        public view_ProgramList()
        {

            vProgram = new ObservableCollection<View_Program>();

   //DBに接続してデータを取得する自作のクラス
            DB_Utils dbu = new DB_Utils();
            OleDbDataReader dr = dbu.getReader("select no,path from test where no = 1);
            /////////////////////////////////////////////////

            while (dr.Read())
            {
                View_Program uset = new View_Program();
                uset.no = (string)dr.GetValue(0);
                uset.path = dr.GetValue(2).ToString();
                vProgram.Add(uset);

            }

            dr.Close();
        }
    }

別のファイルにメンバー変数を定義しています。

        

class View_Program 
    {

        public int no { get; set; }
        public string path { get; set; }

    }

xamlでは以下のようにBindしています。

        <DataGrid Name="d1" 
                  AutoGenerateColumns="False" 
                  ItemsSource="{Binding Path=vProgram}" >

 <!-- textBoxの定義など... -->

</DataGrid>

MVVM及びWPFを始めたばかりで、プログラムや言葉の使い方が悪い部分もあるかと思いますが、

何卒、ご助言をよろしくお願い致します。

Triggerを使用してContentプロパティを変更した場合の挙動について

$
0
0

ToggleボタンのCheck状態に応じて、ボタン上に表示する図形を変更したいと考えています。

実現方法として、Triggerを使用してContentプロパティを入れ替えるという方法を試しました。

また、表示している図形の色は、有効状態などの状況に応じて通常のボタン同様に自動で変化してほしかったため、図形のFillプロパティを親ToggleボタンのForegroundとバインドしました。

その状態で動作を試したところ、チェック状態に応じて図形は変わるのですが、チェック状態時の図形の色がうまく取得できずに透明となてしまいます。

Triggerによって丸ごとContentプロパティを差し替えているため、差し替え後の図形オブジェクトが親Toggleボタンを探すことができないのかなと思うのですが、どのような解決方法がありますでしょうか?

下記にXamlを記します。

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"><Grid><StackPanel><CheckBox x:Name="chkEnable" Content="ボタン有効化" HorizontalAlignment="Center"/><ToggleButton IsEnabled="{Binding ElementName=chkEnable, Path=IsChecked}" Height="40" Width="40"><ToggleButton.Style><Style TargetType="ToggleButton"><Setter Property="Content"><Setter.Value><Rectangle Width="20" Height="20" Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Foreground}" /></Setter.Value></Setter><Style.Triggers><Trigger Property="IsChecked" Value="True"><Setter Property="Content"><Setter.Value><Ellipse Width="20" Height="20" Fill="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ToggleButton}, Path=Foreground}" /></Setter.Value></Setter></Trigger></Style.Triggers></Style></ToggleButton.Style></ToggleButton></StackPanel></Grid></Window>

WPF MVVM法 DataGrid  バインドデータを変更しても表示が変わらない。

$
0
0

初投稿になります。

現在WPFでMVVM法を使用し、ソフトを作成しているのですが、DataGridでつまずいています。

どなたか助けていただけると助かります。

MVVM法を学習し始めて最初のソフトなので間違っている部分があると思います。

ソフトは、左のリストからグループを選択して、ボタンを押すと、データグリッド内のスライダーが、レベルマックスになるようなソフトを作成したいのですが、コード内でバインドしている変数の値を変更しても、画面が変わってくれません。

また、スクロールバーを動かすと隠れている部分の値は変わってくれています。


ソフトを簡単にしたサンプルコードを以下に記載します。

まずはXamlから

<Window x:Class="SampleProgram.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local ="clr-namespace:SampleProgram.VIEWMODEL"
        Title="MainWindow" Height="500" Width="600"><Window.DataContext><local:ViewModel /></Window.DataContext><Grid><Grid.RowDefinitions><RowDefinition Height="*" /><RowDefinition Height="*" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="*" /><ColumnDefinition Width="*" /><ColumnDefinition Width="2*" /></Grid.ColumnDefinitions><DataGrid Grid.ColumnSpan="2" ItemsSource="{Binding Path=Model_List}" AutoGenerateColumns="False" SelectedItem="{Binding Path=Current_Model}"><DataGrid.Columns><DataGridTemplateColumn Header="グループ"  Width="*" ><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock  Text="{Binding Path=Group}" HorizontalAlignment="Center" VerticalAlignment="Center" /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid><Button Content="Reset" Grid.Row="1" Name="button1" Margin="20,30" Command="{Binding Path=Data_Reset_Command}" /><Button Content="Full" Name="button2" Grid.Row="1" Grid.Column="1" Margin="20,30" Command="{Binding Path=Data_Full_Command}" /><DataGrid  CanUserAddRows="False" CanUserDeleteRows="False" Grid.Column="2"   AutoGenerateColumns="False" ItemsSource="{Binding Path=Current_Model.Persons}" Grid.RowSpan="2"><DataGrid.Columns><DataGridTemplateColumn Header="ID" Width="*"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=ID}"  /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTemplateColumn Header="フェーダー" Width="5*"><DataGridTemplateColumn.CellTemplate><DataTemplate><Slider Margin="5" Minimum="0" Maximum="255" Value="{Binding Path=Data, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" LargeChange="130" SmallChange="1" /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTemplateColumn Header="レベル" Width="*"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBox  Text="{Binding Path=Data, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" /></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid></Grid></Window>

続いてViewModel

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Input;
using System.ComponentModel;
using SampleProgram.MODEL;

namespace SampleProgram.VIEWMODEL
{
    class ViewModel: ViewModelBase
    {
        private Model_Repositry _repository;

        public ViewModel( )
        {
            _repository = new Model_Repositry();
            _model_list       = _repository.Get_Model_List();
            WireCommands();
        }

        private void WireCommands()
        {
            Data_Full_Command = new Command(Data_Full);
            Data_Reset_Command = new Command(Data_Reset);
        }


        public Command Data_Full_Command
        {
            get;
            private set;
        }
        public void Data_Full()
        {
            Current_Model.Data_Full();
            NotifyPropertyChange("Current_Model");
        }

        public Command Data_Reset_Command
        {
            get;
            private set;
        }
        public void Data_Reset()
        {
            Current_Model.Data_Reset();
            NotifyPropertyChange("Current_Model");
        }

        private List<Model> _model_list;
        public List<Model> Model_List
        {
            get { return this._model_list; }
            set
            {
                this._model_list = value;
                NotifyPropertyChange("Model_List");
            }
        }

        private Model _current_model;
        public Model Current_Model
        {
            get
            {
                return _current_model;
            }

            set
            {
                if (_current_model != value)
                {
                    _current_model = value;
                    NotifyPropertyChange("Current_Model");
                    Data_Full_Command.IsEnabled = true;
                    Data_Reset_Command.IsEnabled = true;
                }
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace SampleProgram
{
    public class Command : ICommand
    {
        private readonly Action _handler;
        private bool _isEnabled;

        public Command(Action handler)
        {
            _handler = handler;
        }

        public bool IsEnabled
        {
            get { return _isEnabled; }
            set
            {
                if (value != _isEnabled)
                {
                    _isEnabled = value;
                    if (CanExecuteChanged != null)
                    {
                        CanExecuteChanged(this, EventArgs.Empty);
                    }
                }
            }
        }

        public bool CanExecute(object parameter)
        {
            return IsEnabled;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            _handler();
        }
    }
}


using System;
using System.ComponentModel;

namespace SampleProgram.VIEWMODEL
{
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void NotifyPropertyChange(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
        }
    }
}

次にModel

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleProgram.MODEL
{
    class Model
    {
        public Model() {
            Persons = new Person[512];
            for (int i = 0; i < 512; i++)
            {
                Person add_data = new Person();
                add_data.ID = i + 1;
                Persons[i] = add_data;
            }

        }

        public int Group
        {
            get;
            set;
        }

        public Person[] Persons
        {
            get;
            set;
        }

        public class Person {
            public int ID
            {
                get;
                set;
            }
            public int Data
            {
                get;
                set;
            }
        }


        public void Data_Full()
        {
            for (int i = 0; i < 512; i++)
            {
                Persons[i].Data = 255;
            }
        }

        public void Data_Reset()
        {
            for (int i = 0; i < 512; i++)
            {
                Persons[i].Data = 0;
            }
        }

    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SampleProgram.MODEL
{
    class Model_Repositry
    {
        public Model_Repositry()
        {
            Creat_List();
        }

        private List<Model> _model_list;
        public List<Model> Get_Model_List()
        {
            return _model_list;
        }

        public void Creat_List() {
            _model_list = new List<Model>();
            for (int i = 0; i < 10; i++)
            {
                Model add_model = new Model();
                add_model.Group = i;
                _model_list.Add(add_model);
            }
        }
    }
}

以上がコードです。

どなたか原因を教えていただけると助かります。

Viewing all 711 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>