teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

アドバイスに基づきソースコード追記

2017/07/01 02:25

投稿

kawauso
kawauso

スコア56

title CHANGED
File without changes
body CHANGED
@@ -13,4 +13,63 @@
13
13
  よろしくお願いします。
14
14
 
15
15
  環境
16
- C#, .NET F/W 4.5, VS2017 Pro
16
+ C#, .NET F/W 4.5, VS2017 Pro
17
+
18
+ --追記
19
+ XAML側
20
+ ```C#
21
+ <UserControl x:Class="WpfApp1.RadioButtonUC"
22
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
23
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
24
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
25
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
26
+ xmlns:local="clr-namespace:WpfApp1"
27
+ mc:Ignorable="d"
28
+ d:DesignHeight="300" d:DesignWidth="300"
29
+ Name="root">
30
+ <UserControl.Resources>
31
+ <ResourceDictionary>
32
+ <local:EnumToBooleanConverter x:Key="EnumToBoolean"/>
33
+ </ResourceDictionary>
34
+ </UserControl.Resources>
35
+
36
+ <StackPanel>
37
+ <RadioButton Content="UC Tyep1"
38
+ IsChecked="{Binding TypeChange,ElementName=root,Converter={StaticResource EnumToBoolean},ConverterParameter=TYPE1,UpdateSourceTrigger=PropertyChanged}"/>
39
+ <RadioButton Content="UC Tyep1"
40
+ IsChecked="{Binding TypeChange,ElementName=root,Converter={StaticResource EnumToBoolean},ConverterParameter=TYPE2,UpdateSourceTrigger=PropertyChanged}"/>
41
+ <RadioButton Content="UC Tyep1"
42
+ IsChecked="{Binding TypeChange,ElementName=root,Converter={StaticResource EnumToBoolean},ConverterParameter=TYPE3,UpdateSourceTrigger=PropertyChanged}"/>
43
+ </StackPanel>
44
+ </UserControl>
45
+ ```
46
+
47
+ コード側
48
+ ```C#
49
+ public partial class RadioButtonUC : UserControl
50
+ {
51
+ public RadioButtonUC()
52
+ {
53
+ InitializeComponent();
54
+ }
55
+
56
+ //--- 依存関係プロパティ
57
+ public static readonly DependencyProperty TypeChangeProperty =
58
+ DependencyProperty.Register(
59
+ "TypeChange",
60
+ typeof(bool),
61
+ typeof(RadioButtonUC),
62
+ new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
63
+
64
+ //--- CLRプロパティ ラップ
65
+ public bool TypeChage
66
+ {
67
+ get { return (bool)GetValue(TypeChangeProperty); }
68
+ set { SetValue(TypeChangeProperty, value); }
69
+ }
70
+ }
71
+ ```
72
+ ソースコードはこのようになっています。
73
+ 上記のコードでは例外が投げられてしまいます。
74
+ System.Windows.Markup.XamlParseException: ''プロパティ'System.Windows.Controls.Primitives.ToggleButton.IsChecked' の Set で例外がスローされました。' 行番号 '18'、行位置 '22'。'
75
+