local wpf binding How should be done? - wpf

guys I wanna use my own "usercontrol" in the main window, but i have problem with this line <local:texttoolbar x:Name="toolbar" DockPanel.Dock="Top">
The name of project is wpfin8 so i put it in the line with namespace
xmlns:local="clr-namespace:wpfin8">
main user control xaml code looks like this
<UserControl x:Class="TextEditor.TextEditorToolbar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="UserControl_Loaded">
and the name is texttoolbar.xaml
The piece of mainwindow code is
<Window x:Class="wpfin8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:wpfin8">
<Menu x:Name="menu"
DockPanel.Dock="Top"></Menu>
<local:texttoolbar x:Name="toolbar" DockPanel.Dock="Top">
<ToolBar>
<Button >open
</Button>
<Button Margin="10,0,0,0">
save
</Button>
</ToolBar>
</local:texttoolbar>
I think i did everything properly and it dont want work and it still underlined with this "the name texttoolbar does not exist in the namespace "clr-namespace:wpfin8" " , I've also tried with the "TextEditorToolbar" , "TextEditor"

U Need to add assembly name also to your UserControl namespace used in MainWindow
like->
xmlns:local="clr-namespace:wpfin8;assembly=wpfin8"
assembly name may be different .. U can check that in your UserControl Properties named under AssemblyNamespace..
Hope it helps..:)

Related

How can I set region Manager for my dialog window in Prism?

I write my app without using Shell. So I created my own Window using IDialogService and opened in one of my modules.
As far, as I am concerned, Region Manager is attached to Shell, but due to the fact I don't have it, region manager doesn't work when I try to navigate from one view to another.
I know that Region Navigation works fine with the shell (I tested it) and the same code stops working when I substitute the shell with IDialogService.
Here is what I have
<Window x:Class="TechDocs.Views.MainSettingsWindowView"
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:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Title="MainSettingsWindow" Height="400" Width="750">
<Grid>
</Grid>
</Window>
Content for the first region. When I click the button, it should navigate to the second region.
<UserControl x:Class="TechDocs.Views.SettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Button Command="{Binding NodeSelectedCommand}" Name="Button"/>
<ContentControl prism:RegionManager.RegionName="region"/>
</Grid>
</UserControl>
In module I connect my root window with UserControl which holds the button and Content control for the second region.
public class SettingsModule : IModule
{
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
var dialogService = _containerProvider.Resolve<IDialogService>();
containerRegistry.RegisterDialog<MainSettingsWindow>("MyWindow");
containerRegistry.RegisterDialog<SettingsView>("customView");
containerRegistry.RegisterForNavigation<MyView>();
dialogService.Show("customView");
}
}
And when I click the button I get in this code
public void SelectedNode()
{
regionManager.RequestNavigate("region", "MyView");
}
RequestNavigate doesn't give any exceptions, but still nothing appears on the screen.
Could you please explain how I should register region manager with my window?
Try to initialize the region manager explicitly in your custom window using the static methods below:
RegionManager.SetRegionName(cc, "region");
RegionManager.SetRegionManager(cc, regionManager);
XAML:
<ContentControl x:Name="cc" prism:RegionManager.RegionName="region"/>

Modern UI ClusteredBarChart Does Not Exist In XML Namespace

I am using Metro charts for creating charts, but when I add chart and debug it says:
Error: The tag 'ClusteredBarChart' does not exist in XML namespace
'clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart'.
Line 325 Position 22.
I have already added dll for WPF in reference and added name space as
xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
I have no clue why it is giving this error?
EDIT:
this is code for adding chart control
<chart:ClusteredBarChart x:Name="barchart1" ChartSubTitle="Population in millions" ChartTitle="Countries by population">
<chart:ClusteredBarChart.Series>
<chart:ChartSeries DisplayMember="Name" ItemsSource="{Binding Path=Populations}" SeriesTitle="World largest populations" ValueMember="Count" />
</chart:ClusteredBarChart.Series>
</chart:ClusteredBarChart>
If you use the DLL under the Binaries/WPF folder, despite the error message, it will still work. If you download and compile the source code and use the resulting DLL from your compilation, the error message goes away.
<Window x:Class="WpfApplication249.MainWindow"
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:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
xmlns:local="clr-namespace:WpfApplication249"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<local:MyViewModel/>
</Window.DataContext>
<Grid>
<chart:ClusteredBarChart x:Name="barchart1"
ChartSubTitle="Population in millions"
ChartTitle="Countries by population">
<chart:ClusteredBarChart.Series>
<chart:ChartSeries DisplayMember="Name"
ItemsSource="{Binding Path=Populations}"
SeriesTitle="World largest populations"
ValueMember="Count" />
</chart:ClusteredBarChart.Series>
</chart:ClusteredBarChart>
</Grid>

xaml desing issue with ZeroProximity.Accordian for window store app

I have the following MainPage.xaml:
<Page
x:Class="ComponentGuidTestUW8.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ComponentGuidTestUW8"
xmlns:controls="using:ZeroProximity.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<controls:Accordion>
<controls:AccordionItem Header="Heading 1">
<controls:AccordionItem.Content>
<TextBlock Text="Texting"/>
</controls:AccordionItem.Content>
</controls:AccordionItem>
</controls:Accordion>
</Grid>
The page does display the Accordion control properly when I run the app but I am getting the following error when I try to design xaml file in VS 2015:
"COMException: Error HRESULT E_FAIL has been returned from a call to a
COM component."
Desing Tab
How do I fix that?
Looks like this is an issue with the control: have you try to contact the author ?

XAML Namespace Beginning with a Number

I have inheritted Button and am trying to add it to my main window.
It doesn't show up in the Toolbox. I have tried rebuilding several times.
I have tried adding xmlns:dc="clr-namespace:123Letters and xmlns:dc="clr-namespace:123Letters;assembly=123Letters to my MainWindow.
My MainWindow is:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="MainWin"
Title="123 Letters">
</Window>
My WeatherStationButton is:
<Button x:Class="WeatherStationButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</Button>
and
Public Class WeatherStationButton
Inherits Button
Public Property WeatherStation As tblWeather
End Class
This is super simple stuff. I believe it's because XAML doesn't allow numbers in the first part of namespaces, but I can not find any reference to that anywhere, so I am asking if I am doing something wrong or is this one of XAML's "features"?
Just realized I could add my answer.
If your project name is 123Letters, you need to add an underscore before the first number when referencing it in XAML like, _123Letters.
Your clr-namespace declaration would then be:
xmlns:dc="clr-namespace:_123Letters"
and you could add your inherited button to your MainWindow like this:
<dc:WeatherStationButton x:Name="btnWS" />

Call instance of class in Xaml

Help me understand.
I create template of SilverlightApplication1 in VS2012. Create in my solution folder Models and add class EmployeeTypes.cs. I need to call up the instance of EmployeeTypes.cs in Xaml file (Home.xaml).
I do so in Home.xaml:
<navigation:Page x:Class="SilverlightApplication1.Home"
xmlns:local="clr-namespace:SilverlightApplication1.Models"
....
....
Then i do so ( all this according tutorial http://weblogs.asp.net/psheriff/archive/2012/04/09/silverlight-tree-view-with-multiple-levels.aspx):
<local:EmployeeTypes x:Key=" employeeTemplate"/>
Here VS2012 says: 'local:EmployeeTypes' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
Where i am wrong???
EmployeeTypes.cs
namespace SilverlightApplication1.Models
{
public class EmpolyeeTypes : List<EmployeeType>
{
public EmpolyeeTypes()
{
EmployeeType type;
type=new EmployeeType("Manager");
type.Employees.Add(new Employee("Michael"));
type.Employees.Add(new Employee("Paul"));
this.Add(type);
type = new EmployeeType("Project Managers");
type.Employees.Add(new Employee("Tim"));
type.Employees.Add(new Employee("John"));
type.Employees.Add(new Employee("David"));
this.Add(type);
}
}
}
<navigation:Page x:Class="SilverlightApplication1.Home"
xmlns:local="clr-namespace:SilverlightApplication1.Models"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
Title="Home"
Style="{StaticResource PageStyle}">
<local:EmployeeTypes x:Key=" employeeTemplate"/>
.......
.......
<Grid x:Name="LayoutRoot">
</Grid>
Try to move it to Resources of one UI control, for example as Resources of Grid :
<Grid x:Name="LayoutRoot">
<Grid.Resources>
<local:EmployeeTypes x:Key=" employeeTemplate"/>
</Grid.Resources>
</Grid>
or as Resources of the page :
<navigation:Page
......
>
<navigation:Page.Resources>
<local:EmployeeTypes x:Key=" employeeTemplate"/>
</navigation:Page.Resources>
</navigation:Page>
PS: my answer came from Windows Phone and WPF background, could be different in silverlight. Not sure.

Resources