Comments (1)
Hello,
For a longer time no answer, so perhaps following could help.... (the solution is based on the ModernFrame element)
I had a similar navigation problem to solve. It was little simpler - just showing a pie chart based on data selected in the tree view (in case of no adequate data selected showing just some default pie chart). Perhaps it will bring an idea how to solve your problem.
I have used the ModernFrame element, with its:
- Source property bound the data based on selected item from the tree view (with own so called UriConverter (try to convert null, string, int.ToString or GetHashCode().ToString() to relative Uri in descending order).
- ContentLoader property bound to own FigurePieContentLoader - which is instantiated once and have all needed properties for needed for retrieving the UserControl to be navigated to - especially the correct selected item from the tree view, which is going to be passed as the data context to the being retrieved view - here is the passing data to the view.
Note in case the value is null, the content loader instantiate the a different control.
(This could be similar to situation to determine whether to instantiate Master view or the detail view ...).
Command bound to tree view changed selection determines the right data to show and set it in the the FigurePieContentLoader and then in the view model it self - in that property bound to the ModernFrame's Source property. This makes the ModernFrame trying to refresh, which call the content loader to get the view. (just an additional note: It seems to be using its own cache for already used Source values, so the content loaded is not called each time, the source is changed).
XAML part:
<mui:ModernFrame
ContentLoader="{Binding Path=FigurePieContentLoader}"
Source="{Binding Path=ChartFigure, Converter={StaticResource ResourceKey=uriCnv}}" />
The view model part:
public ViewModel()
{
// the ViweModel's ctor
// a different initialization code...
// ...
// the update chart command
this.UpdateChartCommand = new RelayCommand<PermutationTreeNode<string>>(UpdateChart);
}
private PermutationTreeNode<string> chartFigure;
public PermutationTreeNode<string> ChartFigure
{
get => chartFigure;
set => Set(ref chartFigure, value, nameof(ChartFigure));
}
private FigurePieContentLoader figurePieContentLoader = new FigurePieContentLoader();
public FigurePieContentLoader FigurePieContentLoader => this.figurePieContentLoader;
private void UpdateChart(PermutationTreeNode<string> node)
{
// a code to determine the primNode .......
if (primNode != this.chartFigure)
{
this.FigurePieContentLoader.ChartFigure = primNode;
this.ChartFigure = primNode; // leads to refresh the pie chart
}
}
}
The content loader:
public class FigurePieContentLoader : DefaultContentLoader
{
public PermutationTreeNode<string> ChartFigure { get; set; }
protected override object LoadContent(Uri uri)
{
if (this.ChartFigure == null) return new DefaultPie();
var view = new FigurePie() { DataContext = this.ChartFigure };
return view;
}
}
The UriConverter:
public class UriConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string str = null;
if (value == null)
{
str = "null";
}
else if (value is string valStr)
{
str = valStr;
}
else if (value is int valInt)
{
str = valInt.ToString();
}
else
{
str = value.GetHashCode().ToString();
}
return new Uri(str, UriKind.Relative);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException("UriConverter Convert Back is not supported!");
}
from mui.
Related Issues (20)
- HOW to use the Themes?
- 当我点击了设置之后tab页还是停留在之前的选项上 HOT 1
- 设置了mui:ModernWindow.TileLinks 点击 “设置”挂掉了 HOT 3
- Project template extension does not work on some systems with VS2015
- Project template creates csproj without ProjectTypeGuids
- How to integrate PRISM in ModernUI-App? HOT 1
- How to set the focus to the loaded URI.
- Add xaml as resource
- Not response ModernWindow when I resize the window.
- Show ModernDialog in a non-modal way, (call Show()) lead to a InvalidOperationException, Should Check if it is modal before assign DialogResult
- mui:ModernFrame Can the animation be removed?
- Is MUI developing stopped? HOT 16
- Templase and background HOT 1
- Flexibility to control text transformation HOT 2
- Who knows how to jump to the TAB page by clicking a table row
- Clone the repo and run, error occured
- [deleted]
- Cannot install version 1.0.9
- screenshots missing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mui.