I am trying to follow these instructions for separating tab content into separate files. Here is my file structure
I am trying to load file 2's content with file 1 so that they work together. Here is file 2:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl x:Key="Tab1Control">
<DataTemplate DataType="TabItem">
<TextBlock Text="Test text"></TextBlock>
</DataTemplate>
</UserControl>
</ResourceDictionary>
And the relevant portion of file 1:
<Window x:Class="MnMCharacterCreator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tabs="TabContent/TabAttributesContent">
...
<!--Creates a tabbing system, with a grid defined by each ItemsControl-->
<TabControl Name="WindowTabs">
<TabItem Name="WindowTab1" Header="Attributes">
<!--This is where the UserControl from file 2 should be loaded-->
After visiting these two related questions (with tens of others) and asking on C# chat, I'm left thinking that this is unusual:
Intellisense shows nothing for <tabs: and even if I manually type an existing name or something, an error message is given, meaning that it is not a designer issue. Here is the full solution in VS2012.
To be specific, the question I am trying to ask is how can I use content from another xaml file? If xmlns isn't possible, what is?
You may want to create a user control for tab item as ,
<UserControl x:Class="WPFSample.TabItem1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<TextBlock Height="100" Width="100" Text="Hi from tab item 1"/>
</Grid>
Then for using this add the namespace in the MainWindow as :
<Window x:Class="WPFSample.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:WPFSample">
<Grid>
<TabControl>
<TabItem Header="XYZ">
<local:TabItem1/>
</TabItem>
</TabControl>
</Grid>
You are ready to use .
Hope you have changed the usercontrol xaml.cs from XYZ : Window to XYZ : UserControl and build the solution once .
Related
I have an Image that I need to load from an external file into a Button.
The Image resides in a folder in the same directory as the final executable file.
/Resources/image.png
It's not included in the Project Resources and it should not be for the needs of the Application.
The Image is loaded and displayed into a UserControl fine, but when I place my UserControl into my main View,
I get the following error:
Cannot locate resource 'views/usercontrols/resources/playerbuttonsicons/repeat-icon.png'.
The UserControl is located under Views/UserControls in my Project Tree as the error says.
I have tried various ways of specifying the image path (absolute, relative, uri, pack etc), but none of them worked.
The problem is to be tackled using xaml only, if possible.
UserControl code:
<UserControl x:Class="MusicPlayer.Views.UserControls.NowPlayingControl"
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:MusicPlayer.Views.UserControls"
mc:Ignorable="d"
d:DesignWidth="400"
x:Name="ParentControl">
<!--Resources-->
<UserControl.Resources>
</UserControl.Resources>
<!--Design-->
<DockPanel x:Name="ParentContainer">
<Button x:Name="btnPlay">
<Button.Background>
<ImageBrush ImageSource="Resources/PlayerButtonsIcons/play-icon.png" />
</Button.Background>
</Button>
</DockPanel>
</UserControl>
MainView code:
<Window x:Class="MusicPlayer.MainView"
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:MusicPlayer"
mc:Ignorable="d"
xmlns:vm="clr-namespace:MusicPlayer.ViewModels"
xmlns:uc="clr-namespace:MusicPlayer.Views.UserControls"
x:Name="ParentControl">
<!--Resources-->
<Window.Resources>
<vm:MainViewModel x:Key="VM" />
</Window.Resources>
<!--Design-->
<Grid x:Name="ParentContainer"
DataContext="{StaticResource VM}">
<uc:NowPlayingControl />
</Grid>
</Window>
I resolved my problem with the following steps.
Included all the external files into my Project Resources. Marked them as Content and Copy Always.
Instead of loading the Images into my UserControl at run-time, I loaded them in my App.xaml Resources.
The Images are now used as StaticResource in my UserControl.
App.xaml
<Application x:Class="MusicPlayer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MusicPlayer"
xmlns:ex="clr-namespace:SharpUtilities.WPF"
StartupUri="Views/MainView.xaml">
<Application.Resources>
<BitmapImage x:Key="PlayerPlayIcon"
UriSource="Resources/play-icon.png" />
</Application.Resources>
</Application>
UserControl.xaml
<UserControl x:Class="MusicPlayer.Views.UserControls.NowPlayingControl"
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:MusicPlayer.Views.UserControls"
mc:Ignorable="d"
d:DesignWidth="400"
x:Name="ParentControl">
<DockPanel x:Name="ParentContainer">
<Button x:Name="btnPlay">
<Button.Background>
<ImageBrush ImageSource="{StaticResource PlayerPlayIcon}" />
</Button.Background>
</Button>
</DockPanel>
</UserControl>
I am trying to use a user control and I have tried a few different solutions but, I have not been able to fix this issue:
In my main window, I have written code like below:
<Window x:Class="WPF_Work_Timer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPF_Work_Timer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TabControl>
...
<TabItem Header="This Week">
<controls.WeekView></controls.WeekView>
<!-- ^Controls is not supported in WPF Error is here. -->
</TabItem>
...
</TabControl>
</Grid>
</Window>
I have written code like below for the User Control:
<UserControl x:Class="WPF_Work_Timer.WeekView"
x:Name="WeekViewControl"
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>
</UserControl>
I have searched for a solution for this issue and I am sure that I am missing something very simple.
The problem is you're using a period . instead of a colon :. Try this:
<controls:WeekView></controls:WeekView>
I need to use the ToolTip on a label inside a xaml
<Page x:Class="xxx.xxx"
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="464" d:DesignWidth="628"
Title="ManagementDetails" Loaded="Page_Loaded">
<Grid>
<Label Margin="0,360,376,91" >
<ToolTipService.ToolTip>
<ToolTip Content="Turtle" />
</ToolTipService.ToolTip>
</Label>
</Grid>
</Page>
this xaml file is used to be a child inside a frame contained in another xaml file
<Window x:Class="xxx.xxxxxx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ViewProject" Height="626" Width="810" >
<Grid Height="600" Width="800">
<Frame Margin="172,136,0,0" Name="frame1" />
</Grid>
</Window>
i embedded the page xaml file inside the frame using
MyClass myClass= new MyClass();
frame1.Navigate(myClass);
if i moved the label with the ToolTip from the page xaml file to the window xaml file the ToolTip work but when use it inside the page xaml file it doesn't work.
what is missing here to make it work inside the page xaml file
Why are you doing it this way?!?
Just do something like:
<Label Name="Some_Label" ToolTip="Turtle"> Fun with labels ...</Label>
Done. Should work inside another or by itself.
Using the ToolTip Control:
The ToolTipService class must be used along with the ToolTip control in order to display a tooltip to our control. For the example I will use an image control, but the following can be applied to each of the controls. Here is the code:
<Image Source="GiantSeaTurtle.jpg" Width="400" Height="300">
<ToolTipService.ToolTip>
<ToolTip Content="Turtle"></ToolTip>
</ToolTipService.ToolTip>
</Image>
Thanks guys for all your answers it seems that is was my fault and feel ashamed, i had duplicate xaml files for the same page and i was editing one and viewing another one. Sorry for this inconvenience and thanks again for your help.
I would like to do something such as the following, but I am getting an error that, "The attribute 'Class' from the XAML namespace is only accepted on the root element." Well, I guess my question is how can I abstract a Window class (in this case, the issue is with SomeOtherWindowClass below) out (since I have this class added to my project as a WPF window), and include it as a sub-window in my project?
<Window x:Class="myLogViewer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="myLogViewer"
Height="600"
Width="800"
Background="Black"
BorderBrush="Black"
Style="{DynamicResource MainWindow}"
WindowStyle="None">
<Grid Background="Black">
<Window x:Name="myOtherLogViewerWindow"
x:Class="myLogViewer.SomeOtherWindowClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Black"
BorderBrush="Black"
Style="{DynamicResource myOtherLogViewerWindow}"
WindowStyle="None"/>
</Grid>
</Window>
I am trying to simply navigate from one .xaml page to another. I realize that the navigation template is built for this but I do not want the mainpage header / content below feel that it brings. Using a blank Silverlight application (C#) I want to move from Page1.xaml to Page2.xaml using a hyperlink button.
On Page1.xaml I have a hyperlink button like this:
<HyperlinkButton Content="Preview Report" Height="24" HorizontalAlignment="Stretch" Margin="98,296,377,21" Name="hyperlinkButton1" NavigateUri="/Page2.xaml" />
this doesn't seem to work. Please help
You will need a navigation frame in your MainPage in order to support this. Start with blank Silverlight Application.
Modify MainPage.xaml to look like:-
<UserControl x:Class="StackoverflowSpikes.NavPage"
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:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<navigation:Frame Source="/Page1.xaml" />
</Grid>
</UserControl>
Add two or more Navigation Page's to your project. Now you can add HyperLinkButton elements to them.