質問編集履歴
1
アドバイスに基づきソースコード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,3 +29,121 @@
|
|
29
29
|
環境
|
30
30
|
|
31
31
|
C#, .NET F/W 4.5, VS2017 Pro
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
--追記
|
36
|
+
|
37
|
+
XAML側
|
38
|
+
|
39
|
+
```C#
|
40
|
+
|
41
|
+
<UserControl x:Class="WpfApp1.RadioButtonUC"
|
42
|
+
|
43
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
44
|
+
|
45
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
46
|
+
|
47
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
48
|
+
|
49
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
50
|
+
|
51
|
+
xmlns:local="clr-namespace:WpfApp1"
|
52
|
+
|
53
|
+
mc:Ignorable="d"
|
54
|
+
|
55
|
+
d:DesignHeight="300" d:DesignWidth="300"
|
56
|
+
|
57
|
+
Name="root">
|
58
|
+
|
59
|
+
<UserControl.Resources>
|
60
|
+
|
61
|
+
<ResourceDictionary>
|
62
|
+
|
63
|
+
<local:EnumToBooleanConverter x:Key="EnumToBoolean"/>
|
64
|
+
|
65
|
+
</ResourceDictionary>
|
66
|
+
|
67
|
+
</UserControl.Resources>
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
<StackPanel>
|
72
|
+
|
73
|
+
<RadioButton Content="UC Tyep1"
|
74
|
+
|
75
|
+
IsChecked="{Binding TypeChange,ElementName=root,Converter={StaticResource EnumToBoolean},ConverterParameter=TYPE1,UpdateSourceTrigger=PropertyChanged}"/>
|
76
|
+
|
77
|
+
<RadioButton Content="UC Tyep1"
|
78
|
+
|
79
|
+
IsChecked="{Binding TypeChange,ElementName=root,Converter={StaticResource EnumToBoolean},ConverterParameter=TYPE2,UpdateSourceTrigger=PropertyChanged}"/>
|
80
|
+
|
81
|
+
<RadioButton Content="UC Tyep1"
|
82
|
+
|
83
|
+
IsChecked="{Binding TypeChange,ElementName=root,Converter={StaticResource EnumToBoolean},ConverterParameter=TYPE3,UpdateSourceTrigger=PropertyChanged}"/>
|
84
|
+
|
85
|
+
</StackPanel>
|
86
|
+
|
87
|
+
</UserControl>
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
コード側
|
94
|
+
|
95
|
+
```C#
|
96
|
+
|
97
|
+
public partial class RadioButtonUC : UserControl
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
public RadioButtonUC()
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
InitializeComponent();
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
//--- 依存関係プロパティ
|
112
|
+
|
113
|
+
public static readonly DependencyProperty TypeChangeProperty =
|
114
|
+
|
115
|
+
DependencyProperty.Register(
|
116
|
+
|
117
|
+
"TypeChange",
|
118
|
+
|
119
|
+
typeof(bool),
|
120
|
+
|
121
|
+
typeof(RadioButtonUC),
|
122
|
+
|
123
|
+
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
//--- CLRプロパティ ラップ
|
128
|
+
|
129
|
+
public bool TypeChage
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
get { return (bool)GetValue(TypeChangeProperty); }
|
134
|
+
|
135
|
+
set { SetValue(TypeChangeProperty, value); }
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
ソースコードはこのようになっています。
|
144
|
+
|
145
|
+
上記のコードでは例外が投げられてしまいます。
|
146
|
+
|
147
|
+
System.Windows.Markup.XamlParseException: ''プロパティ'System.Windows.Controls.Primitives.ToggleButton.IsChecked' の Set で例外がスローされました。' 行番号 '18'、行位置 '22'。'
|
148
|
+
|
149
|
+
¥
|