Navigation from menu frame to content frame - c#

I have found this issue here:
WPF Navigate Pages from outside frame
But never solved, I have the same issue and same window structure:
<DockPanel>
<Frame x:Name="Menu" Source="/Menu.xaml" NavigationUiVisibility="Hidden" />
<Frame x:Name="Content" Source="/Welcome.xaml" NavigationUiVisibility="Hidden" />
</DockPanel>
As you can see, the frames contains some default pages, and Menu frame displays the menu buttons:
<Grid>
<Button x:Name="Contact" Click="Contact_Click" />
<Button x:Name="Discussion" Click="Discussion_Click" />
</Grid>
What I want to do is to change the source in Content, using the buttons in menu, I have already tried:
private void Contact_Click(object sender, RoutedEventArgs e)
{
MainWindow mainWindow = new MainWindow();
mainWindow.Content.NavigationService.Navigate("/Contact.xaml", UriKind.Relative);
}
Sideways, do you think that is better option to take the menu directly into the main window instead of having it inside a different frame?

Related

Frame not updating content source

I'm trying to switch pages on the button click however it seems to load the "DataCollectionPage.xaml.cs but it doesn't appear on the screen.
The frame's Current source doesn't change.
I only seem to be able to change the frame in the constructor, not the click method.
How can I fix this?
MainWindow.xaml.cs
public void ButtonAction()
{
ContentFrame.NavigationService.Navigate(new Uri("Pages/DataCollectionPage.xaml",
UriKind.Relative));
ContentFrame.NavigationService.Refresh();
}
MainWindow.xaml.cs
<Frame Source="/CSA;component/Pages/Landing.xaml" Grid.Row="1" x:Name="ContentFrame"
Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="2" Background="#2C2F33" Opacity="0.85"
/>

How to style default NavigationUI

I'm using a Frame in a Window to display content and I added navigation with
<Frame NavigationUIVisibility="Visible" Name="FrameContent" VerticalAlignment="Stretch" Margin="0,34,-0.8,0.4" Grid.RowSpan="2"/>
And in Window.xsml.cs
FrameContent.Navigate(new HomeView());
And the navigation bar looks like this:
Is there any way of changing the default look of this bar? Or is the only option to create a new one?
In my WPF app I created my own, The simplest version of it was like:
<Grid VerticalAlignment="Top" Height="50" Background="DarkGray">
<StackPanel Orientation="Horizontal">
<Button Content="Back" Click="Back_Btn"/>
<Button Content="Next" Click="Next_Btn"/>
</StackPanel>
</Grid>
In code behind:
private void Next_Btn(object sender, RoutedEventArgs e)
{
if (this.NavigationService.CanGoForward)
NavigationService.GoForward();
else
NavigationService.Navigate(new HomeView());
}
private void Back_Btn(object sender, RoutedEventArgs e)
{
if (this.NavigationService.CanGoBack)
NavigationService.GoBack();
else
NavigationService.Navigate(new HomeView());
}
If you want you can design the buttons with materialdesign package from NuGet for example.
The MVVM version of it is more complex.
There is a way to change the default look of the bar.
Have the xaml file with the frame open.
Open the document outline window.
(From the Visual Studio Toolbar: View => Other Windows => Document Outline)
In the Document Outline window right click on the frame to display a context menu.
Select from the context menu: Edit Template => Edit a Copy...
Press OK on the Create Style Resource window.
Change the contents of Window.Resources to your liking.

C# WPF XAML In Window Messages Boxes

I am new to C# WPF, I have created a Popup window which contains a DataGrid to hold some data. In certain cases if there are any errors in the data I want to display this error in the same popup window at the bottom of the window (See screenshot). The idea is that the user can then click ok and the message will disappear displaying the full datagrid again.
Does anybody know how to do this?
I do not want another popup message box in a separate window, I want all messages to be displayed/stacked in the same pop window as the datagrid.
Below, there are 2 grids in the XAML: There is is the master grid, which contains the DataGrid, and another grid which contains the error UI. The error grid is normally collapsed (Visibility set to Visibility.Collapsed).
When the error message needs to be shown, the error grid's Visibility is set to Visibility.Visible, which shows the grid. When the user clicks on the "Dismiss" button, the error grid's Visibility is set to Visibility.Collapsed.
There is not a separate window or popup. Everything is contained within the master view.
XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<DataGrid>
</DataGrid>
<Button Grid.Column="1" Content="Show Message Window" VerticalAlignment="Center" Click="Button_Click_1"/>
<!-- This is the "error grid"-->
<Grid VerticalAlignment="Bottom" Height="Auto"
Background="AliceBlue" Visibility="Collapsed" Name="grdError">
<TextBlock Text="Oops. This is an error!"/>
<Button Content="Dismiss" HorizontalAlignment="Right" Click="Button_Click_3"/>
</Grid>
</Grid>
Code Behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
grdError.Visibility = Visibility.Visible;
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
grdError.Visibility = Visibility.Collapsed;
}
}

How to replace the details view when toolbar item is invoked?

I have a WPF application using PRISM. The application is divided into two sections. The left pane is a menu pane and the right pane is a details pane. I have a toolbar also in the container pane which is a user control.
Now, I want that when I click the toolbar option I should be able to replace the right pane (details pane) with new user control/window. How can I do that? Currently, I have the following code in the toolbar edit button click which opens a new window I do not want a new window I want to replace the right pane window (details) window.
private void EditButtonClick(object sender, RoutedEventArgs e)
{
Window userEditWindow = new Window
{
Title = "User Edit",
Content = new UserEdit(),
Width = 600,
Height = 600
};
userEditWindow.Show();
}
Here is what the user interface looks like:
_______________________________________________________________________
PRISM shell container begins
________________________________________________________________________
| User control containing toolbar (edit, new, update, delete)
menu user control |____________________________________________________
|details pane user control
|
|
__________________________________________________________________ |_______________________________________________________________
PRISM shell container ends
_________________________________________________________________________
Above you can see the layout of my app! As you can see everything is inside the PRISM shell container. I am handling the events from user control toolbar in the code behind for the usercontrol toolbar as shown above. All I want is to replace the details pane when the toolbar is clicked. But I have no idea how to do that?
Look back at my answer to your previous question. You can then handle the Toolbar event by switching the DataEntryContext to a new instance of a different DataEntryViewModel and using a DataTemplate the UserControl in your Details Pane will change to reflect that.
In the MainView:
<Window
//usual window declarations>
<Window.Resources>
<DataTemplate DataType="{x:Type vm:FirstDetailViewModel}">
<view:FirstDetailView />
</DataTemplate>
<DataTemplate DataType="{x:Type vm:SecondDetailViewModel}">
<view:SecondDetailView />
</DataTemplate>
//more DataTemplates for other data entry views
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<view:ToolbarView Grid.Row="0"
DataContext="{Binding ToolbarContext}" />
<ContentPresenter Grid.Row="1"
Content="{Binding DataEntryContext}" />
</Grid>
</Window>
In the MainViewModel:
private void ToolbarContext_LoadFirstDetailExecuted(object sender, EventArgs e)
{
DataEntryContext = new FirstDetailViewModel();
}
private void ToolbarContext_LoadSecondDetailExecuted(object sender, EventArgs e)
{
DataEntryContext = new SecondDetailViewModel();
}

Sometimes custom loading popup doesn't show

In my application loading popup is shown every time when I call It. But some times It just doesn't show and it is same situation. Popup is a custom UserControl object made with WPF.
Popup is in MainWindow.xaml:
<Viewbox Stretch="Fill">
<Grid>
<Grid x:Name="Body" Height="768" Width="1024" Background="{StaticResource SCBPassiveColor}" />
<src:InfoPane x:Name="InfoPaneMaster" Visibility="Collapsed" VerticalAlignment="Top" HorizontalAlignment="Center" />
</Grid>
</Viewbox>
In the Body of the main window application loads selected layout/view. Before new layout is loaded program calls :
LayoutCommands.DisplayInfoPane(msgLoginSuccess, ROPInfo.Info, null);
implementation:
public void DisplayInfoPane(string infoText, ROPInfo infoType, int? displayTime)
{
StopTimer();
SetTimer(displayTime ?? DefaultDisplayTime);
PrepareInfoPane(infoText, infoType);
colCloseIcon.Width = new GridLength(0);
this.Visibility = Visibility.Visible;
}
The popup automatically closes (sets visibility to collapsed) after default time.
Why sometimes this popup just doesn't show? Is this associated with rendering?

Categories

Resources