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

回答編集履歴

5

見直しキャンペーン中

2023/07/22 06:54

投稿

TN8001
TN8001

スコア10166

answer CHANGED
@@ -1,158 +1,257 @@
1
- いろいろな方法がありそうですが、ぱっと思いついたのはこんなところです。
2
-
3
- 非常にバカバカしい^^;
4
- ```xaml
5
- <ListBox
6
- x:Name="dummy"
7
- Grid.Row="2"
8
- Grid.RowSpan="5">
9
- <TextBlock Margin="3" />
10
- <TextBlock Margin="3" />
11
- <TextBlock Margin="3" />
12
- <TextBlock Margin="3" />
13
- <TextBlock Margin="3" />
14
- </ListBox>
15
- <ListBox
16
- x:Name="lstFamilyName"
17
- Grid.Row="2"
18
- Grid.RowSpan="5"
19
- Height="{Binding ActualHeight, ElementName=dummy}">
20
- </ListBox>
21
- ```
22
-
23
- 手元では動いたが、確実に`listBoxItem`が取れるのかは自信なし。
24
- ```C#
25
- private void Window_Loaded(object sender, RoutedEventArgs e)
26
- {
27
- var listBoxItem = lstFamilyName.ItemContainerGenerator.ContainerFromItem(lstFamilyName.ItemsSource.Cast<object>().First()) as ListBoxItem;
28
- lstFamilyName.Height = listBoxItem.ActualHeight * 5 + 4; // 4=BorderのPadding BorderThickness分
29
- }
30
- ```
31
-
32
- ---
33
-
34
- WPFに標準でフォントダイアログがあればこんな苦労いらないですがね^^;(私も作りました)
35
-
36
- ---
37
-
38
- 追記 質問を読めてませんでした^^;
39
-
40
- ```xaml
41
- <Window
42
- x:Class="Questions264300.MainWindow"
43
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
45
- Loaded="Window_Loaded" SizeToContent="WidthAndHeight">
46
- <Window.Resources>
47
- <DataTemplate x:Key="FontTemplate">
48
- <StackPanel Orientation="Horizontal">
49
- <TextBlock
50
- Margin="3"
51
- VerticalAlignment="Center"
52
- Text="{Binding}" />
53
- <TextBlock
54
- VerticalAlignment="Center"
55
- FontFamily="{Binding}"
56
- Text="Sample" />
57
- </StackPanel>
58
- </DataTemplate>
59
- </Window.Resources>
60
- <StackPanel Orientation="Horizontal">
61
-
62
- <ListBox
63
- x:Name="lstFamilyName0"
64
- VerticalAlignment="Top"
65
- ItemTemplate="{StaticResource FontTemplate}" />
66
- <ListBox
67
- x:Name="lstFamilyName1"
68
- VerticalAlignment="Top"
69
- ItemTemplate="{StaticResource FontTemplate}" />
70
- <ListBox
71
- x:Name="lstFamilyName3"
72
- VerticalAlignment="Top"
73
- ItemTemplate="{StaticResource FontTemplate}" />
74
- <ListBox
75
- x:Name="lstFamilyName5"
76
- VerticalAlignment="Top"
77
- ItemTemplate="{StaticResource FontTemplate}" />
78
- <ListBox
79
- x:Name="lstFamilyName"
80
- VerticalAlignment="Top"
81
- ItemTemplate="{StaticResource FontTemplate}" />
82
-
83
- </StackPanel>
84
- </Window>
85
- ```
86
-
87
- ```C#
88
- using System;
89
- using System.Collections.Generic;
90
- using System.Linq;
91
- using System.Windows;
92
- using System.Windows.Controls;
93
- using System.Windows.Markup;
94
- using System.Windows.Media;
95
-
96
- namespace Questions264300
97
- {
98
- public partial class MainWindow : Window
99
- {
100
- public MainWindow()
101
- {
102
- InitializeComponent();
103
- lstFamilyName0.ItemsSource = SystemFontsModel.SystemFonts.Take(0);
104
- lstFamilyName1.ItemsSource = SystemFontsModel.SystemFonts.Take(1);
105
- lstFamilyName3.ItemsSource = SystemFontsModel.SystemFonts.Take(3);
106
- lstFamilyName5.ItemsSource = SystemFontsModel.SystemFonts.Take(5);
107
- lstFamilyName.ItemsSource = SystemFontsModel.SystemFonts;
108
- }
109
-
110
- private void Window_Loaded(object sender, RoutedEventArgs e)
111
- {
112
- {
113
- var listBoxItem = lstFamilyName0.ItemContainerGenerator.ContainerFromItem(lstFamilyName0.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
114
- lstFamilyName0.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
115
- }
116
- {
117
- var listBoxItem = lstFamilyName1.ItemContainerGenerator.ContainerFromItem(lstFamilyName1.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
118
- lstFamilyName1.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
119
- }
120
- {
121
- var listBoxItem = lstFamilyName3.ItemContainerGenerator.ContainerFromItem(lstFamilyName3.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
122
- lstFamilyName3.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
123
- }
124
- {
125
- var listBoxItem = lstFamilyName5.ItemContainerGenerator.ContainerFromItem(lstFamilyName5.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
126
- lstFamilyName5.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
127
- }
128
- {
129
- var listBoxItem = lstFamilyName.ItemContainerGenerator.ContainerFromItem(lstFamilyName.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
130
- lstFamilyName.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
131
- }
132
- }
133
-
134
- class SystemFontsModel
135
- {
136
- private static ICollection<FontFamily> _SystemFonts;
137
- public static ICollection<FontFamily> SystemFonts => _SystemFonts ??= GetSystemFonts();
138
-
139
- private static ICollection<FontFamily> GetSystemFonts()
140
- {
141
- var systemFonts = new List<FontFamily>();
142
- var jp = XmlLanguage.GetLanguage("ja-jp");
143
- var us = XmlLanguage.GetLanguage("en-us");
144
- foreach(var font in Fonts.SystemFontFamilies)
145
- {
146
- if(font.FamilyNames.ContainsKey(jp)) systemFonts.Add(new FontFamily(font.FamilyNames[jp]));
147
- else if(font.FamilyNames.ContainsKey(us)) systemFonts.Add(new FontFamily(font.FamilyNames[us]));
148
- else systemFonts.Add(new FontFamily(font.FamilyNames.First().Value));
149
- }
150
- systemFonts.Sort((x, y) => string.Compare(x.Source, y.Source, StringComparison.Ordinal));
151
- return systemFonts;
152
- }
153
- }
154
- }
155
- }
156
- ```
157
- ![アプリ画像](383a253147c4a02b7d63b9e94837986c.png)
158
- 多分ほかのリストボックスにも適用するんでしょうから、ビヘイビアのほうがいいでしょうね^^;
1
+ いろいろな方法がありそうですが、ぱっと思いついたのはこんなところです。
2
+
3
+ 非常にバカバカしい^^;
4
+ ```xml
5
+ <ListBox
6
+ x:Name="dummy"
7
+ Grid.Row="2"
8
+ Grid.RowSpan="5">
9
+ <TextBlock Margin="3" />
10
+ <TextBlock Margin="3" />
11
+ <TextBlock Margin="3" />
12
+ <TextBlock Margin="3" />
13
+ <TextBlock Margin="3" />
14
+ </ListBox>
15
+ <ListBox
16
+ x:Name="lstFamilyName"
17
+ Grid.Row="2"
18
+ Grid.RowSpan="5"
19
+ Height="{Binding ActualHeight, ElementName=dummy}">
20
+ </ListBox>
21
+ ```
22
+
23
+ ---
24
+
25
+ 追記
26
+ `Height`でなく`MaxHeight`にすべきだった。
27
+
28
+ ```xml
29
+ <Window
30
+ x:Class="Questions264300.MainWindow"
31
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
32
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
+ xmlns:local="clr-namespace:Questions264300"
34
+ Title="フォントの選択"
35
+ MinWidth="542"
36
+ ResizeMode="NoResize"
37
+ SizeToContent="WidthAndHeight"
38
+ WindowStyle="SingleBorderWindow">
39
+ <Window.Resources>
40
+ <local:Point2PixelConverter x:Key="point2PixelConverter" />
41
+ </Window.Resources>
42
+
43
+ <DockPanel
44
+ Margin="10"
45
+ TextBlock.FontFamily="{Binding SelectedValue, ElementName=lstFamilyName, Mode=TwoWay}"
46
+ TextBlock.FontSize="{Binding SelectedValue, ElementName=lstFontSize, Mode=TwoWay, Converter={StaticResource point2PixelConverter}}">
47
+ <Grid Margin="0,10,0,0" DockPanel.Dock="Bottom">
48
+ <Grid.ColumnDefinitions>
49
+ <ColumnDefinition Width="2*" />
50
+ <ColumnDefinition Width="1*" />
51
+ <ColumnDefinition Width="5" />
52
+ <ColumnDefinition Width="1*" />
53
+ </Grid.ColumnDefinitions>
54
+
55
+ <Button
56
+ Grid.Column="1"
57
+ Content="OK"
58
+ IsDefault="True" />
59
+ <Button
60
+ Grid.Column="3"
61
+ Content="キャンセル"
62
+ IsCancel="True" />
63
+ </Grid>
64
+
65
+ <Grid>
66
+ <Grid.ColumnDefinitions>
67
+ <ColumnDefinition Width="2.5*" />
68
+ <ColumnDefinition Width="5" />
69
+ <ColumnDefinition Width="2.5*" />
70
+ <ColumnDefinition Width="5" />
71
+ <ColumnDefinition Width="1*" />
72
+ </Grid.ColumnDefinitions>
73
+ <Grid.RowDefinitions>
74
+ <RowDefinition Height="Auto" />
75
+ <RowDefinition Height="Auto" />
76
+ <RowDefinition Height="Auto" />
77
+ <RowDefinition Height="Auto" />
78
+ <RowDefinition />
79
+ <RowDefinition Height="Auto" />
80
+ <RowDefinition Height="Auto" />
81
+ </Grid.RowDefinitions>
82
+
83
+ <Label Content="フォント(_F)" Target="{Binding ElementName=txtFamilyName}" />
84
+ <TextBox
85
+ x:Name="txtFamilyName"
86
+ Grid.Row="1"
87
+ FontWeight="Bold" />
88
+
89
+ <ListBox
90
+ x:Name="dummy"
91
+ Grid.Row="2"
92
+ Grid.RowSpan="5"
93
+ VerticalAlignment="Top"
94
+ Visibility="Hidden">
95
+ <TextBlock Margin="3" />
96
+ <TextBlock Margin="3" />
97
+ <TextBlock Margin="3" />
98
+ <TextBlock Margin="3" />
99
+ <TextBlock Margin="3" />
100
+ <TextBlock Margin="3" />
101
+ <TextBlock Margin="3" />
102
+ <TextBlock Margin="3" />
103
+ <TextBlock Margin="3" />
104
+ <TextBlock Margin="3" />
105
+ </ListBox>
106
+ <ListBox
107
+ x:Name="lstFamilyName"
108
+ Grid.Row="2"
109
+ Grid.RowSpan="5"
110
+ MaxHeight="{Binding ActualHeight, ElementName=dummy}"
111
+ ItemsSource="{x:Static local:SystemFontsModel.SystemFonts}">
112
+ <ListBox.ItemTemplate>
113
+ <DataTemplate>
114
+ <StackPanel Orientation="Horizontal">
115
+ <TextBlock
116
+ Margin="3"
117
+ VerticalAlignment="Center"
118
+ Text="{Binding}" />
119
+ <TextBlock
120
+ VerticalAlignment="Center"
121
+ FontFamily="{Binding}"
122
+ Text="Sample" />
123
+ </StackPanel>
124
+ </DataTemplate>
125
+ </ListBox.ItemTemplate>
126
+ </ListBox>
127
+
128
+ <Label
129
+ Grid.Column="2"
130
+ Content="タイプフェース(_Y)"
131
+ Target="{Binding ElementName=txtTypeface}" />
132
+ <TextBox
133
+ x:Name="txtTypeface"
134
+ Grid.Row="1"
135
+ Grid.Column="2"
136
+ FontWeight="Bold" />
137
+ <ListBox
138
+ x:Name="lstTypeface"
139
+ Grid.Row="2"
140
+ Grid.Column="2" />
141
+ <Label
142
+ Grid.Row="3"
143
+ Grid.Column="2"
144
+ Content="サンプル(_M)"
145
+ Target="{Binding ElementName=txtSample}" />
146
+ <TextBox
147
+ Name="txtSample"
148
+ Grid.Row="4"
149
+ Grid.Column="2"
150
+ Grid.ColumnSpan="3"
151
+ AcceptsReturn="True"
152
+ TextWrapping="Wrap"
153
+ ToolTip="テキストの編集可能" />
154
+ <Label
155
+ Grid.Row="5"
156
+ Grid.Column="2"
157
+ Content="言語(_L)"
158
+ Target="{Binding ElementName=cmbLanguage}" />
159
+ <ComboBox
160
+ x:Name="cmbLanguage"
161
+ Grid.Row="6"
162
+ Grid.Column="2"
163
+ Grid.ColumnSpan="3" />
164
+
165
+ <Label
166
+ Grid.Column="4"
167
+ Content="サイズ(_S)"
168
+ Target="{Binding ElementName=txtFontSize}" />
169
+ <TextBox
170
+ x:Name="txtFontSize"
171
+ Grid.Row="1"
172
+ Grid.Column="4"
173
+ FontWeight="Bold" />
174
+
175
+ <ListBox
176
+ x:Name="dummy2"
177
+ Grid.Row="2"
178
+ Grid.Column="4"
179
+ VerticalAlignment="Top"
180
+ Visibility="Hidden">
181
+ <ListBoxItem>0</ListBoxItem>
182
+ <ListBoxItem>0</ListBoxItem>
183
+ <ListBoxItem>0</ListBoxItem>
184
+ <ListBoxItem>0</ListBoxItem>
185
+ <ListBoxItem>0</ListBoxItem>
186
+ </ListBox>
187
+ <ListBox
188
+ x:Name="lstFontSize"
189
+ Grid.Row="2"
190
+ Grid.Column="4"
191
+ MaxHeight="{Binding ActualHeight, ElementName=dummy2}"
192
+ ItemsSource="{Binding Sizes}"
193
+ SelectedIndex="5" />
194
+ </Grid>
195
+ </DockPanel>
196
+ </Window>
197
+ ```
198
+
199
+ ```cs
200
+ using System;
201
+ using System.Collections.Generic;
202
+ using System.Globalization;
203
+ using System.Linq;
204
+ using System.Windows;
205
+ using System.Windows.Data;
206
+ using System.Windows.Markup;
207
+ using System.Windows.Media;
208
+
209
+ namespace Questions264300
210
+ {
211
+ public partial class MainWindow : Window
212
+ {
213
+ public int[] Sizes { get; } = { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, };
214
+
215
+ public MainWindow()
216
+ {
217
+ InitializeComponent();
218
+ DataContext = this;
219
+ }
220
+ }
221
+
222
+ public class SystemFontsModel
223
+ {
224
+ private static ICollection<FontFamily> _SystemFonts;
225
+ public static ICollection<FontFamily> SystemFonts => _SystemFonts ??= GetSystemFonts();
226
+
227
+ private static ICollection<FontFamily> GetSystemFonts()
228
+ {
229
+ var systemFonts = new List<FontFamily>();
230
+ var jp = XmlLanguage.GetLanguage("ja-jp");
231
+ var us = XmlLanguage.GetLanguage("en-us");
232
+ foreach (var font in Fonts.SystemFontFamilies)
233
+ {
234
+ if (font.FamilyNames.ContainsKey(jp)) systemFonts.Add(new FontFamily(font.FamilyNames[jp]));
235
+ else if (font.FamilyNames.ContainsKey(us)) systemFonts.Add(new FontFamily(font.FamilyNames[us]));
236
+ else systemFonts.Add(new FontFamily(font.FamilyNames.First().Value));
237
+ }
238
+ systemFonts.Sort((x, y) => string.Compare(x.Source, y.Source, StringComparison.Ordinal));
239
+ return systemFonts;
240
+ }
241
+ }
242
+
243
+ public class Point2PixelConverter : IValueConverter
244
+ {
245
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
246
+ => value is int point ? point * (96.0 / 72.0) : DependencyProperty.UnsetValue;
247
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
248
+ }
249
+ }
250
+
251
+ ```
252
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-07-22/027dd677-2626-4235-b078-b5be96f75aa8.png)
253
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-07-22/28cf91f7-00b2-4ea1-b8f6-1d24bcae28fa.png)
254
+
255
+ ---
256
+
257
+ ぶっちゃけこんな(選択したフォントサイズと連動する)ダイアログ絶対イヤですけどね(サンプル欄の意味って。。。)

4

質問を読めてませんでした^^;

2020/05/25 12:22

投稿

TN8001
TN8001

スコア10166

answer CHANGED
@@ -31,4 +31,128 @@
31
31
 
32
32
  ---
33
33
 
34
- WPFに標準でフォントダイアログがあればこんな苦労いらないのですがね^^;(私も作りました)
34
+ WPFに標準でフォントダイアログがあればこんな苦労いらないのですがね^^;(私も作りました)
35
+
36
+ ---
37
+
38
+ 追記 質問を読めてませんでした^^;
39
+
40
+ ```xaml
41
+ <Window
42
+ x:Class="Questions264300.MainWindow"
43
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
45
+ Loaded="Window_Loaded" SizeToContent="WidthAndHeight">
46
+ <Window.Resources>
47
+ <DataTemplate x:Key="FontTemplate">
48
+ <StackPanel Orientation="Horizontal">
49
+ <TextBlock
50
+ Margin="3"
51
+ VerticalAlignment="Center"
52
+ Text="{Binding}" />
53
+ <TextBlock
54
+ VerticalAlignment="Center"
55
+ FontFamily="{Binding}"
56
+ Text="Sample" />
57
+ </StackPanel>
58
+ </DataTemplate>
59
+ </Window.Resources>
60
+ <StackPanel Orientation="Horizontal">
61
+
62
+ <ListBox
63
+ x:Name="lstFamilyName0"
64
+ VerticalAlignment="Top"
65
+ ItemTemplate="{StaticResource FontTemplate}" />
66
+ <ListBox
67
+ x:Name="lstFamilyName1"
68
+ VerticalAlignment="Top"
69
+ ItemTemplate="{StaticResource FontTemplate}" />
70
+ <ListBox
71
+ x:Name="lstFamilyName3"
72
+ VerticalAlignment="Top"
73
+ ItemTemplate="{StaticResource FontTemplate}" />
74
+ <ListBox
75
+ x:Name="lstFamilyName5"
76
+ VerticalAlignment="Top"
77
+ ItemTemplate="{StaticResource FontTemplate}" />
78
+ <ListBox
79
+ x:Name="lstFamilyName"
80
+ VerticalAlignment="Top"
81
+ ItemTemplate="{StaticResource FontTemplate}" />
82
+
83
+ </StackPanel>
84
+ </Window>
85
+ ```
86
+
87
+ ```C#
88
+ using System;
89
+ using System.Collections.Generic;
90
+ using System.Linq;
91
+ using System.Windows;
92
+ using System.Windows.Controls;
93
+ using System.Windows.Markup;
94
+ using System.Windows.Media;
95
+
96
+ namespace Questions264300
97
+ {
98
+ public partial class MainWindow : Window
99
+ {
100
+ public MainWindow()
101
+ {
102
+ InitializeComponent();
103
+ lstFamilyName0.ItemsSource = SystemFontsModel.SystemFonts.Take(0);
104
+ lstFamilyName1.ItemsSource = SystemFontsModel.SystemFonts.Take(1);
105
+ lstFamilyName3.ItemsSource = SystemFontsModel.SystemFonts.Take(3);
106
+ lstFamilyName5.ItemsSource = SystemFontsModel.SystemFonts.Take(5);
107
+ lstFamilyName.ItemsSource = SystemFontsModel.SystemFonts;
108
+ }
109
+
110
+ private void Window_Loaded(object sender, RoutedEventArgs e)
111
+ {
112
+ {
113
+ var listBoxItem = lstFamilyName0.ItemContainerGenerator.ContainerFromItem(lstFamilyName0.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
114
+ lstFamilyName0.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
115
+ }
116
+ {
117
+ var listBoxItem = lstFamilyName1.ItemContainerGenerator.ContainerFromItem(lstFamilyName1.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
118
+ lstFamilyName1.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
119
+ }
120
+ {
121
+ var listBoxItem = lstFamilyName3.ItemContainerGenerator.ContainerFromItem(lstFamilyName3.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
122
+ lstFamilyName3.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
123
+ }
124
+ {
125
+ var listBoxItem = lstFamilyName5.ItemContainerGenerator.ContainerFromItem(lstFamilyName5.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
126
+ lstFamilyName5.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
127
+ }
128
+ {
129
+ var listBoxItem = lstFamilyName.ItemContainerGenerator.ContainerFromItem(lstFamilyName.ItemsSource.Cast<object>().FirstOrDefault()) as ListBoxItem;
130
+ lstFamilyName.MaxHeight = (listBoxItem?.ActualHeight * 5 + 4) ?? 0; // 4=Border Padding BorderThickness分
131
+ }
132
+ }
133
+
134
+ class SystemFontsModel
135
+ {
136
+ private static ICollection<FontFamily> _SystemFonts;
137
+ public static ICollection<FontFamily> SystemFonts => _SystemFonts ??= GetSystemFonts();
138
+
139
+ private static ICollection<FontFamily> GetSystemFonts()
140
+ {
141
+ var systemFonts = new List<FontFamily>();
142
+ var jp = XmlLanguage.GetLanguage("ja-jp");
143
+ var us = XmlLanguage.GetLanguage("en-us");
144
+ foreach(var font in Fonts.SystemFontFamilies)
145
+ {
146
+ if(font.FamilyNames.ContainsKey(jp)) systemFonts.Add(new FontFamily(font.FamilyNames[jp]));
147
+ else if(font.FamilyNames.ContainsKey(us)) systemFonts.Add(new FontFamily(font.FamilyNames[us]));
148
+ else systemFonts.Add(new FontFamily(font.FamilyNames.First().Value));
149
+ }
150
+ systemFonts.Sort((x, y) => string.Compare(x.Source, y.Source, StringComparison.Ordinal));
151
+ return systemFonts;
152
+ }
153
+ }
154
+ }
155
+ }
156
+ ```
157
+ ![アプリ画像](383a253147c4a02b7d63b9e94837986c.png)
158
+ 多分ほかのリストボックスにも適用するんでしょうから、ビヘイビアのほうがいいでしょうね^^;

3

サイズ調整

2020/05/25 12:22

投稿

TN8001
TN8001

スコア10166

answer CHANGED
@@ -6,11 +6,11 @@
6
6
  x:Name="dummy"
7
7
  Grid.Row="2"
8
8
  Grid.RowSpan="5">
9
- <TextBlock />
9
+ <TextBlock Margin="3" />
10
- <TextBlock />
10
+ <TextBlock Margin="3" />
11
- <TextBlock />
11
+ <TextBlock Margin="3" />
12
- <TextBlock />
12
+ <TextBlock Margin="3" />
13
- <TextBlock />
13
+ <TextBlock Margin="3" />
14
14
  </ListBox>
15
15
  <ListBox
16
16
  x:Name="lstFamilyName"
@@ -25,7 +25,7 @@
25
25
  private void Window_Loaded(object sender, RoutedEventArgs e)
26
26
  {
27
27
  var listBoxItem = lstFamilyName.ItemContainerGenerator.ContainerFromItem(lstFamilyName.ItemsSource.Cast<object>().First()) as ListBoxItem;
28
- lstFamilyName.Height = listBoxItem.ActualHeight * 5;
28
+ lstFamilyName.Height = listBoxItem.ActualHeight * 5 + 4; // 4=BorderのPadding BorderThickness分
29
29
  }
30
30
  ```
31
31
 

2

5

2020/05/24 03:32

投稿

TN8001
TN8001

スコア10166

answer CHANGED
@@ -11,7 +11,6 @@
11
11
  <TextBlock />
12
12
  <TextBlock />
13
13
  <TextBlock />
14
- <TextBlock />
15
14
  </ListBox>
16
15
  <ListBox
17
16
  x:Name="lstFamilyName"

1

5

2020/05/24 03:10

投稿

TN8001
TN8001

スコア10166

answer CHANGED
@@ -12,7 +12,6 @@
12
12
  <TextBlock />
13
13
  <TextBlock />
14
14
  <TextBlock />
15
- <TextBlock />
16
15
  </ListBox>
17
16
  <ListBox
18
17
  x:Name="lstFamilyName"
@@ -27,7 +26,7 @@
27
26
  private void Window_Loaded(object sender, RoutedEventArgs e)
28
27
  {
29
28
  var listBoxItem = lstFamilyName.ItemContainerGenerator.ContainerFromItem(lstFamilyName.ItemsSource.Cast<object>().First()) as ListBoxItem;
30
- lstFamilyName.Height = listBoxItem.ActualHeight * 6;
29
+ lstFamilyName.Height = listBoxItem.ActualHeight * 5;
31
30
  }
32
31
  ```
33
32