質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Windows Server

Windows Serverとは、Microsoft社のサーバ用オペレーティングシステムの総称です。 企業内ネットワークなどで利用されるサーバ機へ導入することを想定して開発されているため高い安定性があり、 管理機能を提供するソフトウェアが多く含まれています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

解決済

1回答

1877閲覧

RadioButtonが表示されない

Turkeyman

総合スコア3

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Windows Server

Windows Serverとは、Microsoft社のサーバ用オペレーティングシステムの総称です。 企業内ネットワークなどで利用されるサーバ機へ導入することを想定して開発されているため高い安定性があり、 管理機能を提供するソフトウェアが多く含まれています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

1グッド

0クリップ

投稿2021/07/12 01:44

編集2021/07/13 23:53

お世話になっております。

Visual Studio 2012を用いて、WPFをC#で作ろうと思っています。
Windows10だとRadioBouttonにチェック入れたときに表示されるのですが、Windows Server 2012だとRadioBouttonにカーソルを合わせないとチェックが表示されません。CheckBoxもこのような状態になりましたが、以前の質問で解決することができました。どうぞよろしくお願いします。

補足情報(FW/ツールのバージョンなど)

開発環境 Windows10
テスト環境 Windows Server 2012
Visual Studio 2012

該当のソースコード

ソースコード <!-- ***************** RadioButtonStyle Windows Server 2012表示用 *****************--> <Style x:Key="RadioButtonStyleDisplay" TargetType="{x:Type RadioButton}"> <Setter Property="FocusVisualStyle"> <Setter.Value> <Style> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Ellipse Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> <Setter Property="Background" Value="White"/> <Setter Property="BorderBrush" Value="#FF707070"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RadioButton}"> <Grid x:Name="templateRoot" Background="Transparent"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <Border x:Name="RadioButtonBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> <Grid x:Name="markGrid"> <Path x:Name="optionMark" Data="F1M9.97498,1.22334L4.6983,9.09834 4.52164,9.09834 0,5.19331 1.27664,3.52165 4.255,6.08833 8.33331,1.52588E-05 9.97498,1.22334z" Fill="#FF212121" Margin="1" Opacity="0" Stretch="None"/> <Ellipse x:Name="indeterminateMark" Fill="#FF212121" Margin="2" Opacity="0"/> </Grid> </Border> <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="1" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="HasContent" Value="True"> <Setter Property="FocusVisualStyle"> <Setter.Value> <Style> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Margin="14,0,0,0" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> </ControlTemplate> </Setter.Value> </Setter> </Style> </Setter.Value> </Setter> <Setter Property="Padding" Value="4,-1,0,0"/> </Trigger> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" TargetName="RadioButtonBorder" Value="#FFF3F9FF"/> <Setter Property="BorderBrush" TargetName="RadioButtonBorder" Value="#FF5593FF"/> <Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/> <Setter Property="Fill" TargetName="indeterminateMark" Value="#FF212121"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" TargetName="RadioButtonBorder" Value="#FFE6E6E6"/> <Setter Property="BorderBrush" TargetName="RadioButtonBorder" Value="#FFBCBCBC"/> <Setter Property="Fill" TargetName="optionMark" Value="#FF707070"/> <Setter Property="Fill" TargetName="indeterminateMark" Value="#FF707070"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" TargetName="RadioButtonBorder" Value="#FFD9ECFF"/> <Setter Property="BorderBrush" TargetName="RadioButtonBorder" Value="#FF3C77DD"/> <Setter Property="Fill" TargetName="optionMark" Value="#FF212121"/> <Setter Property="Fill" TargetName="indeterminateMark" Value="#FF212121"/> </Trigger> <Trigger Property="IsChecked" Value="True"> <Setter Property="Opacity" TargetName="optionMark" Value="1"/> <Setter Property="Opacity" TargetName="indeterminateMark" Value="0"/> </Trigger> <Trigger Property="IsChecked" Value="{x:Null}"> <Setter Property="Opacity" TargetName="optionMark" Value="0"/> <Setter Property="Opacity" TargetName="indeterminateMark" Value="1"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
TN8001👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

juner

2021/07/12 02:45

とりあえず再現コード(というかプロジェクト)が無いとなんとも答えられないのでは……?
juner

2021/07/12 04:29

コードを記述する場合は、マークダウンを使用して シンタックスハイライトを利かせてください。 wpf の xaml 中にコメントを書く場合は xml のコメントである <!-- comment --> な構文を使うとよいと思います。
TN8001

2021/07/12 10:09

前回のCheckBoxから考えてこれもStyleが原因だと思うんですが、 この部分のコードを出して意味がありますか? 前回と同じようにStyleを出すと、これもVisualStateベースになってしまうということですか? (こちらでは逆にどうやってもVisualStateベースで出せなくなってしまっています^^; Triggerベースのを出すのはやぶさかではありませんが、おそらくSetterのForegroundを変えるだけでいいと思うのですが。
TN8001

2021/07/14 00:51

この提示のStyleって [WPF CheckBox not displaying checked in Window Server 2012. Is this bug or feature?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/e85cd47a-1bfc-4201-949f-4ae49a6930ac/wpf-checkbox-not-displaying-checked-in-window-server-2012-is-this-bug-or-feature?forum=wpf のCheckBoxの文字をRadioButtonに置換しただけですよね? それではラジオボタンにならないじゃないですか。 VSでStyleの出し方がわからないんですか? 私がVS2019で出したStyleを提示すれば解決できそうですか? 全体的に説明不足です。 あなたにとって当たり前のことでも他人にはわかりません。 ちょっとくどいかなと思うくらいでちょうどいいです。
Turkeyman

2021/07/14 00:59

前回のを使えば行けると思っていました。Styleを出すとはどういうことですか?
TN8001

2021/07/14 01:04

> Styleを出すとはどういうことですか? 前回の質問への追記・修正の依頼 TN8001 2021/07/08 16:46 の > Visual StudioあるいはBlend for Visual Studioで、「テンプレートの編集」ー「コピーして編集」で出力されたものでしょうか? の操作のことです。
Turkeyman

2021/07/14 01:27

他人が書いたコードを先輩から「バグ直して」と渡されたものなので、「テンプレートの編集」ー「コピーして編集」で出力されたものかどうかわかりません。私の環境ではデザインも見れないので、検証もできないです。ですが、おそらくそれらで出力されたものかと思います。
guest

回答1

0

ベストアンサー

これで解決するかは不明ですが、Windows 10 & Visual Studio 2019で出したStyleを提示しておきます。

Style出力

xml

1<Window 2 x:Class="Questions349003.MainWindow" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 Width="800" 6 Height="450"> 7 <Window.Resources> 8 <Style x:Key="FocusVisual"> 9 <Setter Property="Control.Template"> 10 <Setter.Value> 11 <ControlTemplate> 12 <Rectangle Margin="2" StrokeDashArray="1 2" SnapsToDevicePixels="true" StrokeThickness="1" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 13 </ControlTemplate> 14 </Setter.Value> 15 </Setter> 16 </Style> 17 <Style x:Key="OptionMarkFocusVisual"> 18 <Setter Property="Control.Template"> 19 <Setter.Value> 20 <ControlTemplate> 21 <Rectangle Margin="14,0,0,0" StrokeDashArray="1 2" SnapsToDevicePixels="true" StrokeThickness="1" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 22 </ControlTemplate> 23 </Setter.Value> 24 </Setter> 25 </Style> 26 <SolidColorBrush x:Key="RadioButton.Static.Background" Color="#FFFFFFFF"/> 27 <SolidColorBrush x:Key="RadioButton.Static.Border" Color="#FF707070"/> 28 <SolidColorBrush x:Key="RadioButton.Static.Glyph" Color="#FF212121"/> 29 <SolidColorBrush x:Key="RadioButton.MouseOver.Background" Color="#FFF3F9FF"/> 30 <SolidColorBrush x:Key="RadioButton.MouseOver.Border" Color="#FF5593FF"/> 31 <SolidColorBrush x:Key="RadioButton.MouseOver.Glyph" Color="#FF212121"/> 32 <SolidColorBrush x:Key="RadioButton.Pressed.Background" Color="#FFD9ECFF"/> 33 <SolidColorBrush x:Key="RadioButton.Pressed.Border" Color="#FF3C77DD"/> 34 <SolidColorBrush x:Key="RadioButton.Pressed.Glyph" Color="#FF212121"/> 35 <SolidColorBrush x:Key="RadioButton.Disabled.Background" Color="#FFE6E6E6"/> 36 <SolidColorBrush x:Key="RadioButton.Disabled.Border" Color="#FFBCBCBC"/> 37 <SolidColorBrush x:Key="RadioButton.Disabled.Glyph" Color="#FF707070"/> 38 <Style TargetType="{x:Type RadioButton}"> 39 <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> 40 <Setter Property="Background" Value="{StaticResource RadioButton.Static.Background}"/> 41 <Setter Property="BorderBrush" Value="{StaticResource RadioButton.Static.Border}"/> 42 <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 43 <Setter Property="BorderThickness" Value="1"/> 44 <Setter Property="Template"> 45 <Setter.Value> 46 <ControlTemplate TargetType="{x:Type RadioButton}"> 47 <Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True"> 48 <Grid.ColumnDefinitions> 49 <ColumnDefinition Width="Auto"/> 50 <ColumnDefinition Width="*"/> 51 </Grid.ColumnDefinitions> 52 <Border x:Name="radioButtonBorder" Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="100" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1,1,2,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"> 53 <Grid x:Name="markGrid" Margin="2"> 54 <Ellipse x:Name="optionMark" Fill="{StaticResource RadioButton.Static.Glyph}" MinHeight="6" MinWidth="6" Opacity="0"/> 55 </Grid> 56 </Border> 57 <ContentPresenter x:Name="contentPresenter" Grid.Column="1" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 58 </Grid> 59 <ControlTemplate.Triggers> 60 <Trigger Property="HasContent" Value="true"> 61 <Setter Property="FocusVisualStyle" Value="{StaticResource OptionMarkFocusVisual}"/> 62 <Setter Property="Padding" Value="4,-1,0,0"/> 63 </Trigger> 64 <Trigger Property="IsMouseOver" Value="true"> 65 <Setter Property="Background" TargetName="radioButtonBorder" Value="{StaticResource RadioButton.MouseOver.Background}"/> 66 <Setter Property="BorderBrush" TargetName="radioButtonBorder" Value="{StaticResource RadioButton.MouseOver.Border}"/> 67 <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource RadioButton.MouseOver.Glyph}"/> 68 </Trigger> 69 <Trigger Property="IsEnabled" Value="false"> 70 <Setter Property="Background" TargetName="radioButtonBorder" Value="{StaticResource RadioButton.Disabled.Background}"/> 71 <Setter Property="BorderBrush" TargetName="radioButtonBorder" Value="{StaticResource RadioButton.Disabled.Border}"/> 72 <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource RadioButton.Disabled.Glyph}"/> 73 </Trigger> 74 <Trigger Property="IsPressed" Value="true"> 75 <Setter Property="Background" TargetName="radioButtonBorder" Value="{StaticResource RadioButton.Pressed.Background}"/> 76 <Setter Property="BorderBrush" TargetName="radioButtonBorder" Value="{StaticResource RadioButton.Pressed.Border}"/> 77 <Setter Property="Fill" TargetName="optionMark" Value="{StaticResource RadioButton.Pressed.Glyph}"/> 78 </Trigger> 79 <Trigger Property="IsChecked" Value="true"> 80 <Setter Property="Opacity" TargetName="optionMark" Value="1"/> 81 </Trigger> 82 <Trigger Property="IsChecked" Value="{x:Null}"> 83 <Setter Property="Opacity" TargetName="optionMark" Value="0.56"/> 84 </Trigger> 85 </ControlTemplate.Triggers> 86 </ControlTemplate> 87 </Setter.Value> 88 </Setter> 89 </Style> 90 </Window.Resources> 91 <Grid> 92 <RadioButton Content="Content" /> 93 </Grid> 94</Window>

出力の際に「すべてに適用」にしておくと、Styleをつけて回る手間が省けます。

投稿2021/07/14 01:16

編集2023/07/28 13:50
TN8001

総合スコア9321

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Turkeyman

2021/07/14 23:49

ありがとうございました。理解するのに時間かかりましたが、手順とスタイルを参考にして変更したらうまくいきました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問