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

回答編集履歴

1

見直しキャンペーン中

2023/07/28 17:13

投稿

TN8001
TN8001

スコア10108

answer CHANGED
@@ -1,133 +1,133 @@
1
- やりたいことは単純なうえ需要もありそうなのに、やってみると非常に難しいですね^^;
2
- 長々書いていますが、残念ながら満足いく解決法は見つかりませんでした。。。
3
-
4
- 普通に検索するとこの辺りがすぐ出てきます。
5
- [c# - How can I make a paragraph corners round? - Stack Overflow](https://stackoverflow.com/questions/33367853/how-can-i-make-a-paragraph-corners-round)
6
-
7
- [How do I surround Block content with Borders that have rounded corners?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/7d7c5309-ff6a-403a-82f9-7714213d4122/how-do-i-surround-block-content-with-borders-that-have-rounded-corners)
8
-
9
- しかし`BlockUIContainer`にくるむと、コレジャナイ感がすごいです(これでいいなら話は早いです)
10
-
11
- 2つ目のリンクで言及がある`Adorner`も↓をベースに検討しましたが、位置の更新以前に`Paragraph`のサイズ取得法が見つけられませんでした。
12
- [Create custom FrameworkContentElement to add diagonal line over text in WPF - Stack Overflow](https://stackoverflow.com/questions/5432395/create-custom-frameworkcontentelement-to-add-diagonal-line-over-text-in-wpf)
13
-
14
- `Paragraph`を改造?するような方法も探りましたが、`internal`まみれでどうしようもなさそうでした。
15
-
16
- 発想を変えて`Background`の`VisualBrush`に`Border`を突っ込むという雑な方法でそれっぽくはなりましたが、背景なので内側に描画になるのと`Width`・`Height`を実際のサイズに近い数字にしないと残念なことになります。
17
-
18
- 面倒なのでxamlで書きましたが、C#コードにするのは簡単でしょう。
19
- ```xaml
20
- <Window
21
- x:Class="Questions356645.MainWindow"
22
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
23
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
24
- Width="800"
25
- Height="450">
26
- <Grid>
27
- <RichTextBox Margin="10" BorderThickness="0">
28
- <FlowDocument>
29
- <Paragraph
30
- Margin="150,5,5,5"
31
- BorderBrush="Aqua"
32
- BorderThickness="1"
33
- TextAlignment="Right">
34
- <Run Text="normal" />
35
- </Paragraph>
36
-
37
- <BlockUIContainer>
38
- <Border
39
- Margin="150,5,5,5"
40
- BorderBrush="Aqua"
41
- BorderThickness="1"
42
- CornerRadius="5">
43
- <RichTextBox BorderThickness="0">
44
- <FlowDocument>
45
- <Paragraph TextAlignment="Right">
46
- <Run Text="BlockUIContainer" />
47
- </Paragraph>
48
- </FlowDocument>
49
- </RichTextBox>
50
- </Border>
51
- </BlockUIContainer>
52
-
53
- <Paragraph Margin="150,5,5,5" TextAlignment="Right">
54
- <Paragraph.Background>
55
- <VisualBrush>
56
- <VisualBrush.Visual>
57
- <Border
58
- Width="600"
59
- Height="20"
60
- BorderBrush="Aqua"
61
- BorderThickness="1"
62
- CornerRadius="5" />
63
- </VisualBrush.Visual>
64
- </VisualBrush>
65
- </Paragraph.Background>
66
- <Run Text="VisualBrush" />
67
- </Paragraph>
68
-
69
- <Paragraph
70
- Margin="150,5,5,5"
71
- BorderBrush="Aqua"
72
- BorderThickness="5"
73
- TextAlignment="Right">
74
- <Run Text="normal" />
75
- </Paragraph>
76
-
77
- <BlockUIContainer>
78
- <Border
79
- Margin="150,5,5,5"
80
- BorderBrush="Aqua"
81
- BorderThickness="5"
82
- CornerRadius="5">
83
- <RichTextBox BorderThickness="0">
84
- <FlowDocument>
85
- <Paragraph TextAlignment="Right">
86
- <Run Text="BlockUIContainer" />
87
- </Paragraph>
88
- </FlowDocument>
89
- </RichTextBox>
90
- </Border>
91
- </BlockUIContainer>
92
-
93
- <Paragraph Margin="150,5,5,5" TextAlignment="Right">
94
- <Paragraph.Background>
95
- <VisualBrush>
96
- <VisualBrush.Visual>
97
- <Border
98
- Width="600"
99
- Height="20"
100
- BorderBrush="Aqua"
101
- BorderThickness="5"
102
- CornerRadius="5" />
103
- </VisualBrush.Visual>
104
- </VisualBrush>
105
- </Paragraph.Background>
106
- <Run Text="VisualBrush" />
107
- </Paragraph>
108
-
109
- <Paragraph Margin="150,5,5,5" TextAlignment="Right">
110
- <Paragraph.Background>
111
- <VisualBrush>
112
- <VisualBrush.Visual>
113
- <Border
114
- Width="100"
115
- Height="100"
116
- BorderBrush="Aqua"
117
- BorderThickness="1"
118
- CornerRadius="5" />
119
- </VisualBrush.Visual>
120
- </VisualBrush>
121
- </Paragraph.Background>
122
- <Run Text="VisualBrush" />
123
- </Paragraph>
124
- </FlowDocument>
125
- </RichTextBox>
126
- </Grid>
127
- </Window>
128
- ```
129
- ![アプリ画像](a908bb9cc2d1658048b095ca91579642.png)
130
-
131
- ---
132
-
1
+ やりたいことは単純なうえ需要もありそうなのに、やってみると非常に難しいですね^^;
2
+ 長々書いていますが、残念ながら満足いく解決法は見つかりませんでした。。。
3
+
4
+ 普通に検索するとこの辺りがすぐ出てきます。
5
+ [c# - How can I make a paragraph corners round? - Stack Overflow](https://stackoverflow.com/questions/33367853/how-can-i-make-a-paragraph-corners-round)
6
+
7
+ [How do I surround Block content with Borders that have rounded corners?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/7d7c5309-ff6a-403a-82f9-7714213d4122/how-do-i-surround-block-content-with-borders-that-have-rounded-corners)
8
+
9
+ しかし`BlockUIContainer`にくるむと、コレジャナイ感がすごいです(これでいいなら話は早いです)
10
+
11
+ 2つ目のリンクで言及がある`Adorner`も↓をベースに検討しましたが、位置の更新以前に`Paragraph`のサイズ取得法が見つけられませんでした。
12
+ [Create custom FrameworkContentElement to add diagonal line over text in WPF - Stack Overflow](https://stackoverflow.com/questions/5432395/create-custom-frameworkcontentelement-to-add-diagonal-line-over-text-in-wpf)
13
+
14
+ `Paragraph`を改造?するような方法も探りましたが、`internal`まみれでどうしようもなさそうでした。
15
+
16
+ 発想を変えて`Background`の`VisualBrush`に`Border`を突っ込むという雑な方法でそれっぽくはなりましたが、背景なので内側に描画になるのと`Width`・`Height`を実際のサイズに近い数字にしないと残念なことになります。
17
+
18
+ 面倒なのでxamlで書きましたが、C#コードにするのは簡単でしょう。
19
+ ```xml
20
+ <Window
21
+ x:Class="Questions356645.MainWindow"
22
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
23
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
24
+ Width="800"
25
+ Height="450">
26
+ <Grid>
27
+ <RichTextBox Margin="10" BorderThickness="0">
28
+ <FlowDocument>
29
+ <Paragraph
30
+ Margin="150,5,5,5"
31
+ BorderBrush="Aqua"
32
+ BorderThickness="1"
33
+ TextAlignment="Right">
34
+ <Run Text="normal" />
35
+ </Paragraph>
36
+
37
+ <BlockUIContainer>
38
+ <Border
39
+ Margin="150,5,5,5"
40
+ BorderBrush="Aqua"
41
+ BorderThickness="1"
42
+ CornerRadius="5">
43
+ <RichTextBox BorderThickness="0">
44
+ <FlowDocument>
45
+ <Paragraph TextAlignment="Right">
46
+ <Run Text="BlockUIContainer" />
47
+ </Paragraph>
48
+ </FlowDocument>
49
+ </RichTextBox>
50
+ </Border>
51
+ </BlockUIContainer>
52
+
53
+ <Paragraph Margin="150,5,5,5" TextAlignment="Right">
54
+ <Paragraph.Background>
55
+ <VisualBrush>
56
+ <VisualBrush.Visual>
57
+ <Border
58
+ Width="600"
59
+ Height="20"
60
+ BorderBrush="Aqua"
61
+ BorderThickness="1"
62
+ CornerRadius="5" />
63
+ </VisualBrush.Visual>
64
+ </VisualBrush>
65
+ </Paragraph.Background>
66
+ <Run Text="VisualBrush" />
67
+ </Paragraph>
68
+
69
+ <Paragraph
70
+ Margin="150,5,5,5"
71
+ BorderBrush="Aqua"
72
+ BorderThickness="5"
73
+ TextAlignment="Right">
74
+ <Run Text="normal" />
75
+ </Paragraph>
76
+
77
+ <BlockUIContainer>
78
+ <Border
79
+ Margin="150,5,5,5"
80
+ BorderBrush="Aqua"
81
+ BorderThickness="5"
82
+ CornerRadius="5">
83
+ <RichTextBox BorderThickness="0">
84
+ <FlowDocument>
85
+ <Paragraph TextAlignment="Right">
86
+ <Run Text="BlockUIContainer" />
87
+ </Paragraph>
88
+ </FlowDocument>
89
+ </RichTextBox>
90
+ </Border>
91
+ </BlockUIContainer>
92
+
93
+ <Paragraph Margin="150,5,5,5" TextAlignment="Right">
94
+ <Paragraph.Background>
95
+ <VisualBrush>
96
+ <VisualBrush.Visual>
97
+ <Border
98
+ Width="600"
99
+ Height="20"
100
+ BorderBrush="Aqua"
101
+ BorderThickness="5"
102
+ CornerRadius="5" />
103
+ </VisualBrush.Visual>
104
+ </VisualBrush>
105
+ </Paragraph.Background>
106
+ <Run Text="VisualBrush" />
107
+ </Paragraph>
108
+
109
+ <Paragraph Margin="150,5,5,5" TextAlignment="Right">
110
+ <Paragraph.Background>
111
+ <VisualBrush>
112
+ <VisualBrush.Visual>
113
+ <Border
114
+ Width="100"
115
+ Height="100"
116
+ BorderBrush="Aqua"
117
+ BorderThickness="1"
118
+ CornerRadius="5" />
119
+ </VisualBrush.Visual>
120
+ </VisualBrush>
121
+ </Paragraph.Background>
122
+ <Run Text="VisualBrush" />
123
+ </Paragraph>
124
+ </FlowDocument>
125
+ </RichTextBox>
126
+ </Grid>
127
+ </Window>
128
+ ```
129
+ ![アプリ画像](a908bb9cc2d1658048b095ca91579642.png)
130
+
131
+ ---
132
+
133
133
  もう「htmlかなんかでやったほうがマシなんじゃ?」という気はします^^;