Yesterday I create a project in my disk D partition and I found the images I put into project can't be displayed well. XAML code below is very simple:
<Window x:Class="WpfImageTest.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:local="clr-namespace:WpfImageTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Image Width="300" Height="300" Source="/Resources/Images/Chen.png"/>
</Grid>
</Window>
You can see I write a relative path for Image control's Source property and when I run the application it shows nothing on the interface.But magically I copy all the files into the root of my C partition or D partition of my physical disk and rebuild the project, the application runs properly. This proplem troubles me almost all day , can anyone explain why this thing happens?
The original location of my project is D:\Programming\C#\Practice\WpfImageTest and I have already set all images build property to Copy all the time and Content.
Select your image file in your Solution Browser and set its Build Action to Resource as on image below.
Related
I have been working on a project (C# WPF .NET Framework) for a while now and have got a problem and I
have already tried multiple things to try fix the issue when I build it is successful however
when I try to start/run the wpf it shows in Break Mode:
Cannot locate resource 'mainwindow.xaml
(Full: System.IO.IOException: 'Cannot locate resource 'mainwindow.xaml'.')
For my wpf I renamed everything to MainScreen:
<Window x:Class="***************.MainScreen"
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:***************"
mc:Ignorable="d"
Title="MainScreen" Height="450" Width="800"
AllowsTransparency="True" Background="Transparent"
WindowStyle="None" ResizeMode="NoResize" FontSize="20"
>
If any of you need more information please add a comment with what you need.
Also I did the *'s because this project and name will be used officially, sorry and I hope you can understand.
In App.xaml, make sure StartupUri="MainScreen.xaml" is set up correctly.
I have made several ResourceDictionaries for our applications team to use with their future applications. I have deployed the contents of the class library project containing these dictionaries to a .dll file and would like to be able to use the dictionaries by adding a reference to the .dll file in a new WPF solution where I hope to make a new application.
The Class Library in my example is called "NWF_Class_Library.dll" and is saved in the same folder in windows explorer as the MainWindow.xaml file. Is it possible to retrieve the resource dictionaries from within it?
I have read articles about the best way for an organisation to arrange their xaml resources, so it seems it must be possible, but all I find is ways to use the "//pack:application:..." syntax to reference xaml within the same solution as the wpf application. Here is a snippet of code, with the Source blank because nothing I have written has worked!
We had hoped that we could add the standard configurations as well as our more normal useful methods etc to a file that can be deployed with applications.
<Window x:Class="dll_ref_included.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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary Source=""/>
</Window.Resources>
<Grid>
<Button Style="{StaticResource myButton}">This</Button>
</Grid>
</Window>
Try this:
<ResourceDictionary Source="pack://application:,,,/NWF_Class_Library;component/Dictionary1.xaml"/>
...where "NWF_Class_Library" is the name of the referenced assembly and "Dictionary1.xaml" is the name of the ResourceDictionary that is defined in this project.
You can refer to the documentation for more information about pack URIs and how to use them.
I'm sorry if this comes off as a rookie question, but I have spent more time on this than I care to admit.
I'm trying to have a video autoplay on the program's startup. The main window preview shows that the video has been found; however, when I start the program I get a white screen. If someone could help me that would be much appreciated. Thank you and have a wonderful day!
Below is the entirety of the program's xaml code. I have tried running it in other builds of visual studios with no success - so I don't think it's vs.
<Window x:Class="SUP.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:local="clr-namespace:SUP"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<MediaElement Name="VidPlayer" HorizontalAlignment="Left" Height="321" VerticalAlignment="Top" Width="518" Source="Videos\Vid.mp4" LoadedBehavior="Play"></MediaElement>
</Grid>
</Window>
Make sure your video file has Copy To Ouput Directory set to Copy always or Copy if newer.
Sorry if my question is confusing what im trying to ask is how can i render a page that is located in a folder
for example:
my MainWindow.xaml is located in the root folder
i want to render a page located in "ProjectName/Pages" inside a
In case you are still confused this
ProjectName
-- Pages <--- The page i want to render is in this folder
-- App.config
-- App.xaml
-- MainWndow.xaml <--- i want to render the page here
i dont want to have both page and window in the root of the folder, it will look too messy
Add a new Page to your "Pages" folder. Right-click on the folder in the Solution Explorer in Visual Studio and select Add->New Item and then choose a Page and call it "Page1.xaml" or whatever.
You could then display the Page in your window using a Frame like this:
<Window x:Class="WpfApplication1.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"
mc:Ignorable="d"
Title="Window12" Height="300" Width="300">
<StackPanel>
<Frame x:Name="frame" Source="/Pages/Page1.xaml" />
</StackPanel>
</Window>
XamlParseException occured
Provide value on 'System.Windows.BAML.2006.TypeConverterMarkupExtension' threw an exception
I looked up examples of how to add an icon and it seems simple enough. How can I fix this?
<Window
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" mc:Ignorable="d" x:Class="DTV_Red_Zone_Channel.MainWindow"
Title="DirecTV Red Zone Channel" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize"
Initialized="WindowInitialized" SizeToContent="WidthAndHeight"
Icon="RCS_Generic.ico"> <---- Where it's Erroring
ah... it says it cannot locate resource 'rcs_generic.ico' but i put it in the main directory AND where the executable folder is... so where would i put it then?
You need to include the RSC_Generic.ico in your project (at the root, given your XAML), and make sure that it's properties are set to use a Build Action of Resource.