0
我已經做了一個小應用程序使用WPF有一些控制。其中一個控件是一個名爲Credit
的Textblock,另一個控件是一個Frame,並且在該框架內打開頁面。例如:SendMessage.xaml更新窗口上的文本塊,從頁面
我希望有人能幫助我,解釋是否有一種方法可以按下頁面內的按鈕SendMessage.xaml,並更新包含框架的窗口中的Textblock。
我的窗口XAML
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:testeSMS"
xmlns:Properties="clr-namespace:testeSMS.Properties"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" mc:Ignorable="d"
x:Class="testeSMS.JanelaPrincipal"
x:Name="Window"
Title="JanelaPrincipal"
Width="640" Height="480" WindowStyle="None" BorderThickness="1" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
<Window.Resources>
<Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="closeBT">
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<local:CloseBT x:Name="closeBT" Foreground="{x:Null}" Opacity="0.3"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content="" OpacityMask="Black"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonStyle3" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.5"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="label">
<EasingColorKeyFrame KeyTime="0" Value="#FF33FFFF"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Label x:Name="label" Content="Nome da APP by © Kineth Networks" Foreground="#FF3399FF" FontSize="8"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="MenuBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#F6F6F6" Offset="0.25"/>
<GradientStop Color="#EAE8E8" Offset="0.25"/>
<GradientStop Color="#DCD9D9" Offset="0.8"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="MenuStyle1" TargetType="{x:Type Menu}">
<Setter Property="Background" Value="{StaticResource MenuBackground}"/>
<Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
<Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
<Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
<Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Menu}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMainMenu" Value="True"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RadPanelBarStyle1" TargetType="{x:Type telerik:RadPanelBar}">
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local"/>
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<telerik:PanelBarPanel IsItemsHost="True"/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type telerik:RadPanelBar}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="OrientationStates">
<VisualState x:Name="Vertical">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(telerik:LayoutTransformControl.LayoutTransform)" Storyboard.TargetName="transformationRoot">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<RotateTransform Angle="0"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Horizontal">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="(telerik:LayoutTransformControl.LayoutTransform)" Storyboard.TargetName="transformationRoot">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<RotateTransform Angle="-90"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<telerik:LayoutTransformControl x:Name="transformationRoot" IsTabStop="False" Foreground="#FF2D2C2C">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<ScrollViewer x:Name="ScrollViewer" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalScrollBarVisibility="Auto" IsTabStop="False" Margin="0,-1,0,0" Padding="{TemplateBinding Padding}" VerticalScrollBarVisibility="Auto" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}">
<telerik:StyleManager.Theme>
<telerik:Expression_DarkTheme/>
</telerik:StyleManager.Theme>
<ItemsPresenter/>
</ScrollViewer>
</Border>
</telerik:LayoutTransformControl>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Orientation" Value="Vertical"/>
<Setter Property="IsTabStop" Value="True"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Foreground" Value="#FFDDDDDD"/>
<Setter Property="BorderBrush" Value="#FF595959"/>
<Setter Property="Background" Value="#FF3D3D3D"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
<Style x:Key="ButtonStyle2" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#F3F3F3" Offset="0"/>
<GradientStop Color="#EBEBEB" Offset="0.5"/>
<GradientStop Color="#DDDDDD" Offset="0.5"/>
<GradientStop Color="#CDCDCD" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
<Style x:Key="ButtonStyle4" TargetType="{x:Type Button}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
<Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding IsDefaulted}" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" OpacityMask="Black"/>
</Microsoft_Windows_Themes:ButtonChrome>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="RenderDefaulted" TargetName="Chrome" Value="true"/>
</Trigger>
<Trigger Property="ToggleButton.IsChecked" Value="true">
<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ButtonStyle5" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="label">
<EasingColorKeyFrame KeyTime="0" Value="#FF4FAAFF"/>
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed"/>
<VisualState x:Name="Disabled"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Label x:Name="label" Content="[Logout]" Foreground="White" FontSize="10.667"/>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True"/>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#00F0F0FF" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Window.Background>
<Window.Effect>
<DropShadowEffect/>
</Window.Effect>
<Grid x:Name="LayoutRoot">
<Grid.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFF0F0FF" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
<Rectangle MouseDown="Rectangle_MouseDown_1" Height="66" VerticalAlignment="Top" Width="639">
<Rectangle.Stroke>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF1D2D42" Offset="0"/>
<GradientStop Color="#FF35537A" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Stroke>
<Rectangle.OpacityMask>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF1D2D42" Offset="0"/>
<GradientStop Color="#FF35537A" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Image Height="66" Margin="0,0,477.5,0" Source="logo2.png" Stretch="Fill" VerticalAlignment="Top" OpacityMask="Black">
<Image.Effect>
<DropShadowEffect BlurRadius="10" RenderingBias="Quality" ShadowDepth="4"/>
</Image.Effect>
</Image>
<Button Content="Button" Click="Button_Click_1" Height="10" Margin="0,0,6,464" Style="{DynamicResource ButtonStyle1}" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="12"/>
<Button Content="Button" Click="Button_Click_2" Height="1.667" Margin="0,13.583,20.653,0" Style="{DynamicResource ButtonStyle1}" VerticalAlignment="Top" HorizontalAlignment="Right" Width="9.833"/>
<Label Content="Nome da App © Kineth Networks" Margin="285.5,0,160.006,-2.96" VerticalAlignment="Bottom" FontSize="9.333" Foreground="#80000000" FontWeight="Bold"/>
<Frame x:Name="mainFrame" Content=". . ." Margin="0,66,0,23.453" HorizontalAlignment="Right" Width="513" NavigationUIVisibility="Hidden" />
<DockPanel LastChildFill="False" Margin="0,66,0,0" HorizontalAlignment="Left" Width="125" Background="#FF3D3D3D">
<telerik:RadPanelBar Focusable="False" Height="174.5" Width="123" Margin="0,0,0,235.5" telerik:StyleManager.Theme="Expression_Dark" BorderThickness="0" Background="#FF3D3D3D" BorderBrush="Black" VerticalAlignment="Bottom" HorizontalAlignment="Center" Style="{DynamicResource RadPanelBarStyle1}">
<telerik:RadPanelBarItem DropPosition="Inside" Header="Contactos" Width="123" Background="{x:Null}" BorderBrush="#5A000000" FontWeight="Bold" Margin="0,0,0,1" BorderThickness="1,0,1,1">
<telerik:RadPanelBarItem Click="RadPanelBarItem_Click_2" Header="Inserir" Width="100" HorizontalAlignment="Left" Margin="0,2,0,0"/>
<telerik:RadPanelBarItem Click="RadPanelBarItem_Click_5" Header="Listar" Width="100" HorizontalAlignment="Left" Margin="0,1,0,0"/>
</telerik:RadPanelBarItem>
<telerik:RadPanelBarItem DropPosition="Inside" Header="Grupos" Width="123" Background="{x:Null}" BorderBrush="#59000000" FontWeight="Bold" Margin="0,0,0,1">
<telerik:RadPanelBarItem Click="RadPanelBarItem_Click_3" Header="Inserir" Width="100" HorizontalAlignment="Left" Margin="0,2,0,0"/>
<telerik:RadPanelBarItem Click="RadPanelBarItem_Click_4" Header="Listar" Width="100" HorizontalAlignment="Left" Margin="0,1,0,0" IsExpanded="True"/>
</telerik:RadPanelBarItem>
<telerik:RadPanelBarItem DropPosition="Inside" Header="SMS" Width="123" Background="{x:Null}" BorderBrush="#59000000" FontWeight="Bold" Margin="0,0,0,1">
<telerik:RadPanelBarItem Click="RadPanelBarItem_Click_1" Header="Enviar" Width="100" HorizontalAlignment="Left" Margin="0,2,0,0"/>
</telerik:RadPanelBarItem>
<telerik:RadPanelBarItem DropPosition="Inside" Header="Info" Width="123" Background="{x:Null}" BorderBrush="#59000000" FontWeight="Bold" Margin="0,0,0,1">
<telerik:RadPanelBarItem Header="Historico" Width="100" HorizontalAlignment="Left" Margin="0,1,0,0"/>
<telerik:RadPanelBarItem Header="Creditos" Width="100" HorizontalAlignment="Left" Margin="0,1,0,0"/>
</telerik:RadPanelBarItem>
<telerik:RadPanelBarItem DropPosition="Inside" Header="Pacotes" Width="123" Background="{x:Null}" BorderBrush="#59000000" FontWeight="Bold" Margin="0,0,0,1" BorderThickness="1,1,1,2">
<telerik:RadPanelBarItem Header="Gerir" Width="100" HorizontalAlignment="Left" Margin="0,1,0,0"/>
</telerik:RadPanelBarItem>
</telerik:RadPanelBar>
</DockPanel>
<TextBlock x:Name="labelCredito" Text="0 sms" HorizontalAlignment="Right" Margin="0,51,68,0" VerticalAlignment="Top" Foreground="White" FontFamily="/testeSMS;component/Fonts/#Segoe UI" FontSize="10.667" IsManipulationEnabled="True"/>
<Label Content="Username:" HorizontalAlignment="Right" Margin="0,30,61.899,0" VerticalAlignment="Top" FontSize="10.667" Foreground="White"/>
<Label x:Name="lb_username" Content="Son Goku" HorizontalAlignment="Right" Margin="0,30,0,0" VerticalAlignment="Top" Foreground="White" FontSize="10.667" FontWeight="Bold"/>
<Button Content="Button" HorizontalAlignment="Right" Height="23.959" Margin="0,45,5.5,0" Style="{DynamicResource ButtonStyle5}" VerticalAlignment="Top" Width="49.879" Click="Logout_Butt"/>
</Grid>
隱藏文件中的代碼的方法,打開一個頁面
private void RadPanelBarItem_Click_1(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
mainFrame.Source = new Uri("SmS_Enviar.xaml", UriKind.Relative);
}
和SmS_Enviar.xaml頁面上我有一個方法,當我按一個按鈕做一些操作,操作完成後,我想更新我的「JanelaPrincipal」窗口上的標籤
能否請你告訴你的代碼,並與你正在嘗試做 – MethodMan
我有打開一個網頁的框架 私人無效RadPanelBarItem_Click_1(對象發件人,Telerik的裏面我的主窗口代碼的方法一起去相應的XAML .Windows.RadRoutedEventArgs e) { mainFrame.Source = new Uri(「SmS_Enviar.xaml」,UriKind.Relative); } 在那個頁面裏面我有一些簡單的東西和一個按鈕。 當我按下按鈕我想在我的主窗口上有名爲「labelCredito」的文本塊來更改其文本 xml我的窗口 http://pastebin.com/pR7MHGnQ – Thought
請勿粘貼鏈接粘貼您的實際代碼,這裏的個人可能不會點擊他們不熟悉的鏈接。請將代碼粘貼到您的評論中,作爲原始問題的一部分 – MethodMan