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

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

新規登録して質問してみよう
ただいま回答率
85.50%
WPF

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

Q&A

解決済

1回答

7190閲覧

WPFで×ボタンだけを消したい

cancat

総合スコア313

WPF

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

0グッド

0クリップ

投稿2017/02/22 06:11

編集2017/02/22 06:30

こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。

###前提・実現したいこと
WindowのClose button(右上)だけを消したいです。

###試したこと
http://espresso3389.hatenablog.com/entry/2014/05/01/213140
でControl, Maxmize, Minimizeを設定。

###発生している問題・エラーメッセージ
Close Buttonを消すと、Iconもきえてしまう。

###補足情報(言語/FW/ツール等のバージョンなど)
Microsoft Visual Studio Community 2015
Version 14.0.25424.00 Update 3
Microsoft .NET Framework
Version 4.6.01038

インストールしているバージョン:Community

Visual C# 2015 00322-20000-00000-AA575
Microsoft Visual C# 2015

です。
よろしくお願いします。

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

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

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

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

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

guest

回答1

0

ベストアンサー

以下のサイトが参考になるかもしれません。
システムメニューを操作するビヘイビア


2017/2/24 追記

タイトルバーを編集でぐぐって、以下のサイトを見つけました。
WPF で Zune のようなウィンドウを作る
タイトルバーを削除し、メイン領域の上段をタイトルバーに見立てるように、
自前で作成するようです。

MainWindow.xaml

1<Window x:Class="WpfApplication3.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MainWindow" Height="350" Width="525" SnapsToDevicePixels="True" 5 Background="Black"> 6 <WindowChrome.WindowChrome> 7 <!-- WindowChrome CaptionHeightの高さ分がタイトルバーの高さとして扱う --> 8 <WindowChrome CaptionHeight="{x:Static SystemParameters.CaptionHeight}" 9 ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" /> 10 </WindowChrome.WindowChrome> 11 12 <Window.Resources> 13 <Style x:Key="CaptionButtonStyleKey" TargetType="{x:Type Button}"> 14 <Setter Property="OverridesDefaultStyle" Value="True" /> 15 <Setter Property="Foreground" Value="White" /> 16 <Setter Property="FontFamily" Value="Marlett"/> 17 <Setter Property="IsTabStop" Value="False"/> 18 <Setter Property="HorizontalContentAlignment" Value="Center" /> 19 <Setter Property="VerticalContentAlignment" Value="Center" /> 20 <Setter Property="Margin" Value="2" /> 21 <Setter Property="Padding" Value="1" /> 22 <Setter Property="WindowChrome.IsHitTestVisibleInChrome" Value="True" /> 23 <Setter Property="Template"> 24 <Setter.Value> 25 <ControlTemplate TargetType="{x:Type Button}"> 26 <Border x:Name="border" Background="Transparent" SnapsToDevicePixels="True"> 27 <Border.Effect> 28 <DropShadowEffect Opacity="0"/> 29 </Border.Effect> 30 <VisualStateManager.VisualStateGroups> 31 <VisualStateGroup x:Name="CommonStates"> 32 <VisualState x:Name="Normal"> 33 <Storyboard> 34 <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border"> 35 <EasingDoubleKeyFrame KeyTime="0" Value="0.6"/> 36 </DoubleAnimationUsingKeyFrames> 37 </Storyboard> 38 </VisualState> 39 <VisualState x:Name="MouseOver"> 40 <Storyboard> 41 <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border"> 42 <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 43 </DoubleAnimationUsingKeyFrames> 44 </Storyboard> 45 </VisualState> 46 <VisualState x:Name="Pressed"> 47 <Storyboard> 48 <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="border"> 49 <EasingDoubleKeyFrame KeyTime="0" Value="1"/> 50 </DoubleAnimationUsingKeyFrames> 51 <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.ShadowDepth)" Storyboard.TargetName="border"> 52 <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 53 </DoubleAnimationUsingKeyFrames> 54 <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Color)" Storyboard.TargetName="border"> 55 <EasingColorKeyFrame KeyTime="0" Value="White"/> 56 </ColorAnimationUsingKeyFrames> 57 <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Effect).(DropShadowEffect.Opacity)" Storyboard.TargetName="border"> 58 <EasingDoubleKeyFrame KeyTime="0" Value="0.6"/> 59 </DoubleAnimationUsingKeyFrames> 60 </Storyboard> 61 </VisualState> 62 <VisualState x:Name="Disabled"/> 63 </VisualStateGroup> 64 </VisualStateManager.VisualStateGroups> 65 <ContentPresenter x:Name="contentPresenter" Focusable="False" Margin="{TemplateBinding Padding}" 66 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 67 VerticalAlignment="{TemplateBinding VerticalContentAlignment}" /> 68 </Border> 69 </ControlTemplate> 70 </Setter.Value> 71 </Setter> 72 <Setter Property="FocusVisualStyle" Value="{x:Null}" /> 73 </Style> 74 </Window.Resources> 75 76 <Border BorderBrush="Gray" 77 BorderThickness="1"> 78 <Grid> 79 <!-- イメージとタイトルの追加 --> 80 <StackPanel Orientation="Horizontal" Margin="5" 81 HorizontalAlignment="Left" 82 VerticalAlignment="Top"> 83 <Image Source="./Folder.ico" Width="20" Height="20" /> 84 <TextBlock Text="タイトル" Foreground="White" /> 85 </StackPanel> 86 87 <!-- ×ボタンの削除と、各ボタンのクリックイベントを実装 --> 88 <StackPanel Orientation="Horizontal" Margin="5" 89 HorizontalAlignment="Right" 90 VerticalAlignment="Top"> 91 <Button Name="MinButton" Content="0" Style="{DynamicResource CaptionButtonStyleKey}" Click="Button_Click" /> 92 <Button Name="MaxButton" Content="1" Style="{DynamicResource CaptionButtonStyleKey}" Click="Button_Click" /> 93 <Button Name="OriginalSizeButton" Content="2" Style="{DynamicResource CaptionButtonStyleKey}" Click="Button_Click" /> 94 </StackPanel> 95 </Grid> 96 </Border> 97</Window> 98 99

実行例
実行例

投稿2017/02/23 08:12

編集2017/02/24 07:12
sugar_yas

総合スコア135

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

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

cancat

2017/02/23 09:10

コメントありがとうございます。 だめでした。×を消すと、アイコンもきえました。
cancat

2017/02/26 10:10

ありがとうございます。 簡単にはできないということがわかりました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問