回答編集履歴

2

見直しキャンペーン中

2023/08/14 09:09

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -1,6 +1,6 @@
1
1
  「サイズを入れなければいいんじゃない?」と思いましたが、配置法によってはそうもいかないですかね。
2
2
 
3
- 「wpf cliptobounds not work」あたりのキーワードで検索したところ↓が出ました。
3
+ [wpf cliptobounds not work](https://www.google.co.jp/search?q=wpf+cliptobounds+not+work)」あたりのキーワードで検索したところ↓が出ました。
4
4
  [ClipToBounds="Maybe" « Dr. WPF](http://drwpf.com/blog/2007/12/28/cliptoboundsmaybe/)
5
5
 
6
6
  `GetLayoutClip`をオーバーライドしてみたら、クリップされなくなりました(よくわかっていません^^;

1

見直しキャンペーン中

2023/07/27 14:19

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -1,247 +1,125 @@
1
1
  「サイズを入れなければいいんじゃない?」と思いましたが、配置法によってはそうもいかないですかね。
2
2
 
3
-
4
-
5
3
  「wpf cliptobounds not work」あたりのキーワードで検索したところ↓が出ました。
6
-
7
4
  [ClipToBounds="Maybe" « Dr. WPF](http://drwpf.com/blog/2007/12/28/cliptoboundsmaybe/)
8
-
9
-
10
5
 
11
6
  `GetLayoutClip`をオーバーライドしてみたら、クリップされなくなりました(よくわかっていません^^;
12
7
 
13
-
14
-
15
8
  `Path`はsealedクラスでしたので元からパクりました(internalメンバがいないことによるパフォーマンスペナルティは不明)
16
-
17
9
  [Path.cs](https://source.dot.net/#PresentationFramework/System/Windows/Shapes/Path.cs,ede77210f20e8cf9)
18
10
 
19
11
 
20
-
21
-
22
-
23
- ```xaml
12
+ ```xml
24
-
25
13
  <Window
26
-
27
14
  x:Class="Questions340797.MainWindow"
28
-
29
15
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
30
-
31
16
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
32
-
33
17
  xmlns:local="clr-namespace:Questions340797"
34
-
35
18
  Width="800"
36
-
37
19
  Height="450">
38
-
39
20
  <DockPanel>
40
-
41
21
  <StackPanel DockPanel.Dock="Bottom">
42
-
43
22
  <CheckBox x:Name="checkBox" Content="ClipToBounds" />
44
-
45
23
  <Slider
46
-
47
24
  x:Name="x"
48
-
49
25
  Maximum="50"
50
-
51
26
  Minimum="-50" />
52
-
53
27
  <Slider
54
-
55
28
  x:Name="y"
56
-
57
29
  Maximum="50"
58
-
59
30
  Minimum="-50" />
60
-
61
31
  </StackPanel>
62
32
 
63
-
64
-
65
33
  <Grid>
66
-
67
34
  <Grid.ColumnDefinitions>
68
-
69
35
  <ColumnDefinition />
70
-
71
36
  <ColumnDefinition />
72
-
73
37
  <ColumnDefinition />
74
-
75
38
  </Grid.ColumnDefinitions>
76
-
77
39
 
78
-
79
40
  <GroupBox Header="Original">
80
-
81
41
  <Path
82
-
83
42
  Width="50"
84
-
85
43
  Height="50"
86
-
87
44
  ClipToBounds="{Binding IsChecked, ElementName=checkBox}"
88
-
89
45
  Fill="Red">
90
-
91
46
  <Path.Data>
92
-
93
47
  <EllipseGeometry RadiusX="50" RadiusY="50">
94
-
95
48
  <EllipseGeometry.Transform>
96
-
97
49
  <TranslateTransform X="{Binding Value, ElementName=x}" Y="{Binding Value, ElementName=y}" />
98
-
99
50
  </EllipseGeometry.Transform>
100
-
101
51
  </EllipseGeometry>
102
-
103
52
  </Path.Data>
104
-
105
53
  </Path>
106
-
107
54
  </GroupBox>
108
55
 
109
-
110
-
111
56
  <GroupBox Grid.Column="1" Header="No Size">
112
-
113
57
  <Path
114
-
115
58
  HorizontalAlignment="Center"
116
-
117
59
  VerticalAlignment="Center"
118
-
119
60
  ClipToBounds="{Binding IsChecked, ElementName=checkBox}"
120
-
121
61
  Fill="Red">
122
-
123
62
  <Path.Data>
124
-
125
63
  <EllipseGeometry RadiusX="50" RadiusY="50">
126
-
127
64
  <EllipseGeometry.Transform>
128
-
129
65
  <TranslateTransform X="{Binding Value, ElementName=x}" Y="{Binding Value, ElementName=y}" />
130
-
131
66
  </EllipseGeometry.Transform>
132
-
133
67
  </EllipseGeometry>
134
-
135
68
  </Path.Data>
136
-
137
69
  </Path>
138
-
139
70
  </GroupBox>
140
71
 
141
-
142
-
143
72
  <GroupBox Grid.Column="2" Header="MyPath">
144
-
145
73
  <local:MyPath
146
-
147
74
  Width="50"
148
-
149
75
  Height="50"
150
-
151
76
  ClipToBounds="{Binding IsChecked, ElementName=checkBox}"
152
-
153
77
  Fill="Red">
154
-
155
78
  <local:MyPath.Data>
156
-
157
79
  <EllipseGeometry RadiusX="50" RadiusY="50">
158
-
159
80
  <EllipseGeometry.Transform>
160
-
161
81
  <TranslateTransform X="{Binding Value, ElementName=x}" Y="{Binding Value, ElementName=y}" />
162
-
163
82
  </EllipseGeometry.Transform>
164
-
165
83
  </EllipseGeometry>
166
-
167
84
  </local:MyPath.Data>
168
-
169
85
  </local:MyPath>
170
-
171
86
  </GroupBox>
172
-
173
87
  </Grid>
174
-
175
88
  </DockPanel>
176
-
177
89
  </Window>
178
-
179
90
  ```
180
91
 
181
-
182
-
183
- ```C#
92
+ ```cs
184
-
185
93
  using System.Windows;
186
-
187
94
  using System.Windows.Media;
188
-
189
95
  using System.Windows.Shapes;
190
96
 
191
-
192
-
193
97
  namespace Questions340797
194
-
195
98
  {
196
-
197
99
  public sealed class MyPath : Shape
198
-
199
100
  {
200
-
201
101
  public static readonly DependencyProperty DataProperty
202
-
203
102
  = DependencyProperty.Register(nameof(Data), typeof(Geometry), typeof(MyPath),
204
-
205
103
  new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender), null);
206
-
207
104
  public Geometry Data { get => (Geometry)GetValue(DataProperty); set => SetValue(DataProperty, value); }
208
105
 
209
-
210
-
211
106
  protected override Geometry DefiningGeometry
212
-
213
107
  {
214
-
215
108
  get
216
-
217
109
  {
218
-
219
110
  var data = Data;
220
-
221
111
  if (data == null) data = Geometry.Empty;
222
-
223
112
  return data;
224
-
225
113
  }
226
-
227
114
  }
228
-
229
115
  protected override Geometry GetLayoutClip(Size layoutSlotSize)
230
-
231
116
  => ClipToBounds ? base.GetLayoutClip(layoutSlotSize) : null;
232
-
233
117
  }
234
118
 
235
-
236
-
237
119
  public partial class MainWindow : Window
238
-
239
120
  {
240
-
241
121
  public MainWindow() => InitializeComponent();
242
-
243
122
  }
244
-
245
123
  }
246
-
247
124
  ```
125
+ ![アプリ動画](https://ddjkaamml8q8x.cloudfront.net/questions/2023-07-27/1edf8537-1a94-485f-a4ad-27c2d97f03e1.gif)