こんにちは。
Windows10でWPFのアプリケーションを開発しています。
Visual Studio 2015 Communityを使っています。
###前提・実現したいこと
WindowのHeaderをつくろうとしています。
Styleに設定したTextBoxにcsからアクセスし、内容を書き換えたいです。
###発生している問題・エラーメッセージ
アクセスできずにいます。
###該当のソースコード
xaml
1App.xaml 2<Application x:Class="WpfApplication1.App" 3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 5 xmlns:local="clr-namespace:WpfApplication1" 6 StartupUri="MainWindow.xaml"> 7 <Application.Resources> 8 <!-- Windowの共通表示--> 9 <Style x:Key="CommonWindowStyle" TargetType="Window"> 10 <Setter Property="Template"> 11 <Setter.Value> 12 <ControlTemplate TargetType="Window"> 13 <Grid Margin="5"> 14 <Grid.RowDefinitions> 15 <RowDefinition Height="Auto"/> 16 <RowDefinition Height="*"/> 17 </Grid.RowDefinitions> 18 <!-- ヘッダー --> 19 <Grid Grid.Row="0" Background="#FF24B3D5"> 20 <!-- 共通で使用するオブジェクト --> 21 <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Bottom"> 22 <!-- アプリケーションのタイトル --> 23 <TextBlock 24 Text="ApplicationTitle" 25 Foreground="White" 26 FontWeight="Bold" 27 FontSize="24" 28 Margin="5"/> 29 <!--・Icon--> 30 <Image x:Name="IconImage" MinWidth="50" Margin="2.5" Stretch="UniformToFill" Width="80" Height="80"/> 31 <TextBlock x:Name="UserName" MinWidth="200" Margin="2.5" Foreground="White" FontSize="20"/> 32 </StackPanel> 33 </Grid> 34 <!-- コンテンツ部分 --> 35 <Border Grid.Row="1" Background="{TemplateBinding Background}"> 36 <ContentPresenter /> 37 </Border> 38 </Grid> 39 </ControlTemplate> 40 </Setter.Value> 41 </Setter> 42 </Style> 43 44 </Application.Resources> 45</Application> 46 47 48MainWindow.xaml 49<Window x:Class="WpfApplication1.MainWindow" 50 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 51 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 52 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 53 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 54 xmlns:local="clr-namespace:WpfApplication1" 55 Style="{Binding Source={StaticResource CommonWindowStyle}}" 56 mc:Ignorable="d" 57 Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"> 58 <Grid> 59 60 </Grid> 61</Window> 62 63MainWindow.xaml.cs 64using System.Windows; 65 66namespace WpfApplication1 { 67 public partial class MainWindow : Window { 68 public MainWindow() { 69 InitializeComponent(); 70 } 71 72 private void Window_Loaded(object sender, RoutedEventArgs e) { 73 //ここで、App.xamlのImage x: Name = "IconImage", TextBlock x: Name = "UserName"を呼びたい。 74 75 } 76 } 77} 78
###補足情報(言語/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
です。
よろしくお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/20 01:17
2016/09/20 03:27
2016/09/20 04:48