From getting a little help, I managed to make the window only open once, now I want to change the window to a page. When I do this obviously .Show(); and also .Close(); have no extension method.
Now I added a frame to my Generic page (As this will be on all forms):
<Frame x:Name="FrameNavigate" HorizontalAlignment="Left" Height="300" Margin="1296,52,0,0" VerticalAlignment="Top" Width="300" NavigationUIVisibility="Hidden"/>
And I put the x:Name"FrameNavigate" in the XAML. In the code behind the Generic page, I wanted to add this piece of code to open the page up on the frame.
private void btnHelp_Click(object sender, RoutedEventArgs e)
{
if (help != null)
{
help.Close();
help = null;
}
else
{
help = new xamlHelp();
FrameNavigate.Navigate(new xamlHelp());
}
}
But It says that FrameNavigate doesn't exist?
EDIT:
<Style TargetType="{x:Type local:Master}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Master}">
<StackPanel>
<Canvas Height="50" Margin="0,0,0,0" HorizontalAlignment="Stretch" FlowDirection="RightToLeft">
<Canvas.Background>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
<GradientStop Color="#FFB3DDF2" Offset="1.0"/>
<GradientStop Color="#FFD6E9F4" Offset="0.0"/>
</LinearGradientBrush>
</Canvas.Background>
<Button x:Name="btnHelp" Content="Help" Click="btnHelp_Click" Foreground="#FF7E8385" FontFamily="Calibri" FontSize="18" Margin="110,10,0,0" Height="30" Width="70" Style="{x:Null}" BorderBrush="Transparent" Background="Transparent" Cursor="Hand"/>
<GridSplitter Height="30" Width="1" Margin="95,10,0,0" Background="Gray"/>
<Button x:Name="btnSettings" Content="Settings" Foreground="#FF7E8385" FontFamily="Calibri" FontSize="18" Margin="10,10,0,0" Click="btnSettings_Click" Height="30" Width="70" Style="{x:Null}" BorderBrush="Transparent" Background="Transparent" Cursor="Hand"/>
</Canvas>
<Canvas Width="350" Height="850" Margin="0,0,0,0" VerticalAlignment="Stretch" HorizontalAlignment="Left" FlowDirection="RightToLeft" DockPanel.Dock="Bottom">
<Canvas.Background>
<LinearGradientBrush EndPoint="0,0" StartPoint="0,1">
<GradientStop Color="#FFD6E9F4" Offset="1.0"/>
<GradientStop Color="White" Offset="0.0"/>
</LinearGradientBrush>
</Canvas.Background>
<Frame x:Name="FrameNavigate" HorizontalAlignment="Left" Height="300" Margin="1296,52,0,0" VerticalAlignment="Top" Width="300" NavigationUIVisibility="Hidden"/>
</Canvas>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
EDIT:
I have this code which has got no errors, but when you click the button nothing appears?
Master master = ((Button)sender).TemplatedParent as Master;
Frame frame = (Frame)master.Template.FindName("FrameNavigate",master);
frame.Navigate(new xamlHelp());
Since Frame exists in ControlTemplate, you can't access it directly like this from code behind.
Ask template to get that for you by using FrameworkTemplate.FindName method.
Also you need to get Master control (obviously to get template of Master control) which you can get via accessing TemplatedParent of sender button.
This is how you need to do it:
Master master = ((Button)sender).TemplatedParent as Master;
Frame frame = (Frame)master.Template.FindName("FrameNavigate", master);
frame.Navigate(new xamlHelp());
UPDATED:
The Navigate(TypeName) method takes a Type object!
Frame frame = (Frame)this.FindName("FrameNavigate");
frame.Navigate(typeof(xamlHelp)); //frame.Navigate(help);
Have a look at:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.frame.navigate.aspx
and at:
http://msdn.microsoft.com/en-us/library/windows/apps/hh771188.aspx
ps. Note you are not using your help variable in you else code block.
Related
Using the menu control in a xaml window, I have this annoying white space between the window border and the docking panel.
The menu itself is inside a stackpanel:
<Window x:Class="COZView.Shell"
xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sc="clr-namespace:COZView.StaticContent"
xmlns:ve="clr-namespace:COZView.View_Edit"
Title="COZView" Width="1024" Height="800" Icon="/COZView;component/Images/COZView.png"
Loaded="OnLoaded" IsVisibleChanged="isVisibleChanged" Closing="OnClosing">
<Grid x:Name="ShellRegion">
<StackPanel Height="Auto" Orientation="Vertical">
<Menu x:Name="menu">
<!-- MENU ITEMS REMOVED -->
</Menu>
<Grid x:Name="DockingRegion" >
<ad:DockingManager x:Name="DockManager">
<ad:ResizingPanel>
<ad:DocumentPane Margin="0,0,0,0">
<sc:StartPage Title="Home Page" VerticalContentAlignment="Stretch"
onProjectOpenFail="StartPage_onProjectOpenFail"
onProjectOpenSuccess="StartPage_onProjectOpenSuccess"
onProjectCreateSuccess="StartPage_onProjectCreateSuccess"
onProjectCreateFail="StartPage_onProjectCreateFail"/>
</ad:DocumentPane>
<ad:DockablePane ad:ResizingPanel.ResizeWidth="300" x:Name="ExplorerPane" FontSize="14" FontWeight="Bold">
<sc:AboutTab x:Name="about" Title="About" FontSize="14" FontWeight="Bold"/>
<sc:ProcessExplorer x:Name="pxProcessExplorer" Title="Process Explorer" FontSize="14"/>
<sc:DataExplorer x:Name="adDataExplorer" Title="Data Explorer" FontSize="14"/>
<!--<sc:UREPExplorer x:Name="adUREPExplorer" Title="UREP Custom Navigation" FontSize="14" Visibility="Hidden"/>-->
</ad:DockablePane>
</ad:ResizingPanel>
</ad:DockingManager>
</Grid>
</StackPanel>
</Grid>
How do i remove the white space? Do I have to surrond it in something? Should the menu be in a different container?
Its just the default menu style where Background is defined as
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStop Color="#FFF6F6F6" Offset="0.25" />
<GradientStop Color="#FFEAE8E8" Offset="0.25" />
<GradientStop Color="#FFDCD9D9" Offset="0.8" />
<GradientStop Color="#FFFFFFFF" Offset="1" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
Define a different background if you dont like the #FFFFFFFF bottom line.
I have this XAML code and i want to access either the AccountNameTextBox or the elipse few lines below in order to display that some of the Accounts in the list are expired by adding something next to the name (ex. YouTube(Expired)) or by turning the elipse red. The thing is that i can't access them. I have tried using the VisualTreeHelper functions i saw here
How can I find WPF controls by name or type? and even tried creating some of my own but nothing works. A thing i noticed was that when i used "VirtualTreeHelper.GetChild" on accountListBox the output was a Border Control and it was the only child.
The code is below.
`<StackPanel x:Name="MainStackPanel" Grid.Row="1" Grid.RowSpan="2" DataContext="{StaticResource ResourceKey=accountManager}">
<ListBox x:Name="accountListBox" ItemsSource="{Binding LoadedAccounts}" Height="600" VerticalAlignment="Bottom" Margin="10,10" Background="Transparent" DoubleTapped="accountListBox_DoubleTapped" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10,0,0,0">
<TextBlock x:Name="AccountNameTextBox" Text="{Binding AccountName}" FontFamily="Segoe Script" FontSize="30" Foreground="White"/>
<StackPanel Orientation="Horizontal">
<StackPanel>
<!--<TextBlock Text="{Binding Username}" FontSize="25" Foreground="Lime"/>-->
<TextBlock Text="{Binding Email}" FontStyle="Italic" FontSize="25" Foreground="DarkSeaGreen"/>
<TextBlock Text="{Binding Password}" FontSize="25" Foreground="YellowGreen"/>
</StackPanel>
<Ellipse x:Name="Elipse" Height="Auto" Width="10" Margin="10,0">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="YellowGreen" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>`
Why not using Triggers or Converters?
For that you have to add a single property to your bound items (i called mine IsExpired)
Then in the DataTemplate add the DataTrigger:
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsExpired}" Value="True">
<Setter Property="Visibility" Value="Visible" TargetName="ExpiredTextBlock" />
<Setter Property="Fill" Value="Red" TargetName="Elipse" />
</DataTrigger>
</DataTemplate.Triggers>
A possibility with converter would be to add a Converter-Resource to your DataTemplate:
<DataTemplate.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
</DataTemplate.Resources>
Then add your (Expired) TextBlock to the DataTemplate and bind to the property
<TextBlock Text="(Expired)" Visibility="{Binding IsExpired, Converter={StaticResource BooleanToVisibilityConverter}}"/>
For the Color you could do the same with a BooleanToColorConverter.
If you want to stick to your code approach you have to dive deeper in your visual tree:
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
This helper method finds the first child of a given type.
If you want to find it by name you have to use the name as parameter instead of the generic type and replace the (child as T) check by a name-check.
My personal preferrence would be the solution with the triggers, but it's up to you..
Okay, this is probably something pretty simple that I'm not doing quite right. I am just now learning how to add items dynamically using an ItemsControl as shown below.
<ItemsControl ItemsSource="{Binding Buttons}">
<ItemsControl.Template>
<ControlTemplate>
<Button FontWeight="Bold" Command="{Binding SelectMaterialCommand}" CommandParameter="{Binding CommandParameter}" Width="50" Height="50" Style="{StaticResource RoundedButtonStyle}" Margin="0,0,0,0" Click="Button_Click_2" Content="{Binding .Content}"></Button>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
The ItemsControl ItemsSource Property is bound to an ObservableCollection of Buttons. In code I can create a button, set the Content and CommandParameter properties and add it to the ObservableCollection. When I run the application a button is populated, but I can't get the Content and CommandParameter properties to bind correctly.
I have tried doing several different methods such as Binding Path=., Binding Path=Content, Binding Path=.Content...etc, but nothing seems to be working. Any help would be appreciated.
Following Subramaniam B's advice I got this to work by utilizing a Data Template as shown that is located in my UserControl.Resources section.
<DataTemplate x:Key="temp" DataType="{x:Type local:ButtonModel}">
<telerik:RadButton FontWeight="Bold" FontSize="16" Command="{Binding ButtonCommand}" CommandParameter="{Binding Path=Content}" Width="100" Height="75" Margin="0,0,0,0" MouseLeftButtonUp="Button_Click_2" Content="{Binding Path=Content}">
<telerik:RadButton.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="GhostWhite" Offset="0"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="Gray" Offset="0.5"/>
<GradientStop Color="GhostWhite" Offset="1"/>
</LinearGradientBrush>
</telerik:RadButton.Background>
</telerik:RadButton>
</DataTemplate>
Here is where the template is used were used:
<telerik:RadCarousel Loaded="MaterialCar_Loaded" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" x:Name="MaterialCar" Height="200" Background="Blue" ItemTemplate="{StaticResource temp}" ItemsSource="{Binding Buttons}" Margin="0,0,0,0"/>
In your example you are setting the template for the whole ItemsControl (aka: LIST of buttons) to be A button.
No matter what items are in the Buttons collection, this control will render as a single button. Instead, you need to leave the template for the control itself alone, and use I template for the items that are IN the list.
<ItemsControl ItemsSource="{Binding Buttons}">
<!-- ItemsControl.Template becomes ItemsControl.ItemTemplate below -->
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button FontWeight="Bold" Command="{Binding SelectMaterialCommand}" CommandParameter="{Binding CommandParameter}" Width="50" Height="50" Style="{StaticResource RoundedButtonStyle}" Margin="0,0,0,0" Click="Button_Click_2" Content="{Binding .Content}"></Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I have a common popup in my wpf window and I have a button in the datagrid as well. What I want is to open the popup when the button is clicked. The popup should be independent to each button click. For example, let's say that I have two rows in the datagrid. When I click on the first button popup should appear,then I do some changes to that popup and close it. Now I click the second button it should open a new popup instead of the changes I made before. I'm using a common popup for this. Please anyone tell me is it possible to handle my requirement with common popup window?
XAML
<Popup x:Name="popUpServer" IsOpen="False" Placement="MousePoint" >
<Border Background="#FFEFF2F3" BorderBrush="Black" BorderThickness="1" Width="229" Height="145">
<StackPanel Orientation="Horizontal" Margin="0,0,0,-17">
<Grid Width="227" Margin="0,0,0,10">
<GroupBox Header="Configuration" HorizontalAlignment="Left" Margin="9,6,-9,0" VerticalAlignment="Top" Height="125" Width="211">
<Grid>
<Label Content="Auto Restart" HorizontalAlignment="Left" Margin="10,6,0,0" VerticalAlignment="Top"/>
<ToggleSwitch:HorizontalToggleSwitch x:Name="tsAutoRestart" HorizontalAlignment="Left" Margin="97,10,0,0" VerticalAlignment="Top" Width="46" ThumbSize="22" Height="21" RenderTransformOrigin="3.522,1.048">
<ToggleSwitch:HorizontalToggleSwitch.UncheckedBackground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFC80000" Offset="1"/>
<GradientStop Color="#FF0A0A0A" Offset="0.853"/>
</LinearGradientBrush>
</ToggleSwitch:HorizontalToggleSwitch.UncheckedBackground>
<ToggleSwitch:HorizontalToggleSwitch.CheckedBackground>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#000000" />
<GradientStop Color="#000000" Offset="1" />
</LinearGradientBrush>
</ToggleSwitch:HorizontalToggleSwitch.CheckedBackground>
<ToggleSwitch:HorizontalToggleSwitch.ThumbBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFD6D4D4" />
<GradientStop Color="#FFD6D4D4" Offset="1" />
<GradientStop Color="#FFD6D4D4" Offset="0.02" />
</LinearGradientBrush>
</ToggleSwitch:HorizontalToggleSwitch.ThumbBrush>
</ToggleSwitch:HorizontalToggleSwitch>
<ComboBox x:Name="cbDuration" HorizontalAlignment="Left" VerticalAlignment="Top" Width="92" Margin="97,40,0,0">
<ComboBoxItem Content="30 Minutes"/>
<ComboBoxItem Content="1 Hours"/>
<ComboBoxItem Content="2 Hours"/>
</ComboBox>
<Label Content="After" HorizontalAlignment="Left" VerticalAlignment="Top" Width="83" Margin="9,36,0,0"/>
<Button x:Name="btnApply" Content="Apply" HorizontalAlignment="Left" Margin="125,75,0,0" VerticalAlignment="Top" Width="64" Click="BtnApply_Click"/>
</Grid>
</GroupBox>
</Grid>
</StackPanel>
</Border>
</Popup>
Datagrid
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button x:Name="txtServerInfo" Click="TxtServerInfo_Click" Height="23" Width="28">
<Button.Background>
<ImageBrush ImageSource="img.png"/>
</Button.Background>
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Code behind file
private void TxtServerInfo_Click(object sender, RoutedEventArgs e)
{
popUpServer.IsOpen = true;
}
If you want to use a common popup means better create a popup in a separate user control.then for a button click you can create a new object for the user control and then open the popup by using the user controls object.then the values inside the popup will be independent of the previous button click.
please try the next solution; combine your popup with the button into a separate user control, in that way you can trigger the popup opening based on the button click, and for each button click there will be it's(button) own popup opened there. When you combine the popup and the button together they will have the same data context, thus you will have no problem to make a binding, from the other hand if you want a different data contexts for these controls you can support the user with two dependency properties form that a combined user control.
I'll glad to help if you will have problems with the code, let me know about that.
Regards.
the thing i am battling today is the scrollviewer, and the fact that it blocks my events.SO..here's some xaml:
<ScrollViewer x:Name="scrollv" Panel.ZIndex="15" Margin="8,65.5,0,22" VerticalScrollBarVisibility="Visible" Height="392.5" Background="White" IsHitTestVisible="False">
<Grid x:Name="listaintrebari" Height="Auto" Width="301.5" HorizontalAlignment="Left" VerticalAlignment="Top" Background="White" >
</Grid>
</ScrollViewer>
So the thing is: on the grid which is inside the scrollviewer i programaticly add the questions UserControl...which incidentaly has a button with a click event.My problem is that i cant manage to click the button..it's like the scrollviewer is acting like an invisible shield to protect the usercontrol and the button from the evil Mouse!
Any help apreciated!
EDIT:(this is my questions Usercontrol)
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:eHelper_v3"
mc:Ignorable="d"
x:Class="eHelper_v3.questions"
x:Name="IntrebareControl" Width="330.641" Margin="0" MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"
>
<Grid x:Name="LayoutRoot" ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="0,0,13,0" Height="90" >
<Rectangle x:Name="rect" Panel.ZIndex="20" Height="90" Stroke="#FF0975A3" >
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#1404BFD8" Offset="0.004"/>
<GradientStop Color="#1300A7FF" Offset="0.996"/>
<GradientStop Color="#2B0F82CC" Offset="0.459"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Image x:Name="imagine" HorizontalAlignment="Left" Margin="8,8,0,8" Width="126.667" Stretch="Fill" MouseLeftButtonDown="imagine_MouseLeftButtonDown" />
<TextBlock x:Name="textul" Margin="138.667,8,8,22.5" TextWrapping="Wrap" Text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" FontSize="9.333"/>
<Label x:Name="status" Content="Status" Height="22" Margin="127,0,100,0.5" VerticalAlignment="Bottom" FontSize="9.333" Background="#00894848" Foreground="Red"/>
<Button x:Name="raspundeBtn" Content="Raspunde" HorizontalAlignment="Right" Height="18" Margin="0,0,8,4.5" VerticalAlignment="Bottom" Width="50.974" FontSize="9.333" Click="raspundeBtn_Click"/>
</Grid>
REEDITED ...wrong code inserted...kinda sleepy over here
Perhaps, some control ist in front of your button. To click "through" a control you can use
IsHitTestVisible="false"
Can you post your CommentThat ?
#after your edit:
It seems like your RichTextBox and that FlowDocument lies over the Button.
Add your Button as the last child of your Grid.
The user control is handling the left mouse button so the click does not get to the content.
MouseLeftButtonDown="IntrebareControl_MouseLeftButtonDown"
Does that event get raised?
Just in case someone also has problems with the ScrollViewer preventing mouse button events from firing, I solved this by setting a ZIndex for the corresponding UIElement:
<TextBlock Text="Hello World!" Panel.ZIndex="2" MouseLeftButtonUp="TextBlockMouseLeftButtonUp"/>