I am new to XAML and I am implementing a NavigationView control in my UWP application.
Some details:
Visual Studio 2019
Microsoft.UI.Xaml version 2.6.2 (Nuget Package Installed)
UWP Targets:
Target: Universal Windows
Target Version: Windows 10, version 2004 (10.0; Build 19041)
Min Version: Windows 10 Fall Creators Update (10.0; Build 16299)
I am trying to find the property or style that controls the top left corner radius of the "content" section. I would like to not have a rounded corner there, and just to flow directly to the top but I can't seem to find the correct way to do this. Attached is a picture of the rounded corner I am talking about: content frame.
Here is the XAML for my main page with the navigation menu:
<Page
x:Class="NavTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:local="using:NavTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<muxc:NavigationView x:Name="NavView" Background="Gray">
<muxc:NavigationView.MenuItems>
<muxc:NavigationViewItem Tag="home" Icon="Home" Content="Home"/>
<muxc:NavigationViewItemSeparator/>
<muxc:NavigationViewItemHeader x:Name="MainPagesHeader"
Content="Main pages"/>
<muxc:NavigationViewItem Tag="apps" Content="Apps">
<muxc:NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem Tag="games" Content="Games">
<muxc:NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""/>
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
<muxc:NavigationViewItem Tag="music" Icon="Audio" Content="Music"/>
</muxc:NavigationView.MenuItems>
</muxc:NavigationView>
</Grid>
Does anyone know how I can control the top left corner radius of the navigation menu content item to make it not rounded? Is there a style property I can override or set? Just directly setting the "CornerRadius" property on the NavigationView doesn't seem to make any difference.
Thanks
To change the CornerRadius you have to create your own Style for the control:
1: In Visual Studio rightclick your project and go to "Design in Blend..."
2: After Blend is opened, you go to "Objects and Timeline" and rightclick on your NavigationView, which shows up in the list. In the rightclick menu you go to "Edit template" and from there to "Edit a copy".
3: A little window pops up and you can now enter the name of the style.
4: Visual studio will now create a custom style for your NavigationView and you can customise every little thing of the control.
5: You should be done. And if it doesn't work, write me a comment!
Related
How can I set Opacity of WebView2 control in WPF
I need to change opacity of WebView2 from 0 to 1 by using Storyboard but when I am trying to set "Opacity =0" to WebView2 it doesn't get apply.
So is there any way I can dynamically set its opacity?
WebView2 is not a native wpf control,it does not support transparency settings.
you can use CEFSharp,it provides the same feature of WebView2, and supports transparency settings.
NuGet\Install-Package CefSharp.Wpf -Version 108.4.130
It's simply impossible. WebView2 is HwndHost. it means they are native win32 windows placed exactly in location of specified in your WPF. So It's not a WPF element you can manipulate.
If you want to somehow hide the WebView for a while, you can use Visibility.
<wv2:WebView2 Visibility="Hidden" MinHeight="300" />
Above that control you can show a loading icon or something and animate it, not the WebView itself.
<Grid>
<wv2:WebView2 Visibility="Hidden" Width="500" Height="500" />
<custom:MyFancyLoadingControl Visibility="Visible" Width="500" Height="500" />
</Grid>
I am developing a Visual Studio extension in C# and I would like to display a (waiting) transparent animated gif inside a tool window panel.
I have googled a lot and I only could find very complex solutions involving special dedicated libraries or some equivalent source code to add to my project. For example, I could find this post: How do I get an animated gif to work in WPF?. But I cannot understand why it would require such complex solutions for such a basic feature as animated gifs.
Can't XAML support natively animated gifs?
On my side I tried the following in my XAML file:
<Image Source="pack://application:,,,/MyPlugin;component/Resources/busy.gif"
Width="16" Height="16"/>
The image loads (although not animated) while Visual Studio is in edition mode. However, the image NEVER shows in the experimental instance.
What did I miss?
For example, I could find this post: How do I get an animated gif to
work in WPF?. But I cannot understand why it would require such
complex solutions for such a basic feature as animated gifs.
There're some easy ways to display .gif in wpf. For me, I use WpfAnimatedGif to do this.Simply install the nuget package and add the corresponding xmlns then the gif can display in wpf or vs extension.
For WpfAnimatedGif:
1.Add xmlns:gif="http://wpfanimatedgif.codeplex.com" to the xx.xaml.
2.<Image gif:ImageBehavior.AnimatedSource="xxx/xxx.gif" />
Then the .gif can display in the vs extension.
The format in my project:
<UserControl x:Class="VSIXProject2.ToolWindow1Control"
...
xmlns:gif="http://wpfanimatedgif.codeplex.com"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Name="MyToolWindow">
<Grid>
<StackPanel Orientation="Vertical">
...
<Image gif:ImageBehavior.AnimatedSource="pack://application:,,,/VSIXProject2;component/Resources/time.gif" Height="100" Width="200"/>
</StackPanel>
</Grid>
</UserControl>
Note: To display the image when debugging VS extensions, the source format should be pack://application:,,,/xxx;component/Resources/xxx.gif. It's the different behavior between normal wpf and ToolWindows in vsix. More details see this.
I am working on some WPF app with a main window and with some pages, something weird happened to me, "suddenly" when I move from page 1 to page two this toolbar added himself to my window,
my questions: where did this came from? how to remove/ give it better design, I mean where is the source code of this toolbar
Is this default by Microsoft?
Here is my window class def:
<Window x:Class="Tool.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:Tool"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
ResizeMode="CanResizeWithGrip"
MinWidth="600"
MinHeight="500"
Title="Preparation Tool" Height="600" Width="1080" Icon="icon.ico" Foreground="White" >
You can easily hide that:
<Frame NavigationUIVisibility="Hidden"
But you should use contentcontrol instead of frame and usercontrols instead of pages.
Where did this came from? How to remove it?
It is a built-in navigation chrome in Frame control.
According to Microsoft docs, the navigation chrome is visible when a Frame uses its own journal (see JournalOwnership).
If you don't want that Navigation chrome, you can simply set NavigationUIVisibility property of your frame to Hidden.
<Frame NavigationUIVisibility="Hidden" />
If you don't want history navigation management of the current Frame too, you can set JournalOwnership property of Frame to UsesParentJournal . This makes your Frame use the journal of the next available navigation host up the content tree, if available. Otherwise, navigation history is not maintained for the Frame.
<Frame JournalOwnership="UsesParentJournal" />
Or give it a better design? I mean where is the source code of this toolbar?
In Visual Studio (or Visual Studio Blend that I prefer for UI design stuff) simply right-click on your Frame and then select Edit Template > Edit a copy and put copy of Template in a ResourceDictionary. Then you can modify the template which it's key is FrameNavChromeTemplateKey.
Is this default by Microsoft?
Yes.
P.S. Do not forget that when you set NavigationUIVisibility="Hidden" and JournalOwnership="OwnsJournal", history management for Frame itself is still available and you can navigate between pages with commands like Next/Prev mouse buttons.
I am trying to create my first program in SilverLight. But I can't use the InkCanvas.
Simply, I just:
Create a new project.
Choose SilverLight Application (Framework 4.5)
UnCheck "Host the silverlight application in a website..."
SilverLight version 5
"WCF RIA Services" unchecked
Click on ToolBox > Choose Items > Select InkCanvas from SilverLight components
Add InkCanvas to the form & Change it's background color to black
Click on "Start" (Debug)
But I can't see or use the Canvas.
Here is the XAML:
<UserControl 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:Workspace="clr-namespace:Microsoft.Expression.Prototyping.Workspace;assembly=Microsoft.Expression.Prototyping.Runtime"
x:Class="SilverlightApplication3.MainPage"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid x:Name="LayoutRoot"
Background="White">
<Workspace:InkCanvas HorizontalAlignment="Left"
Height="204"
Margin="36,52,0,0"
VerticalAlignment="Top"
Width="310"
Background="Black" />
</Grid>
</UserControl>
Then I get these 2 errors:
Error 1 Undefined CLR namespace. The 'clr-namespace' URI refers to a
namespace 'Microsoft.Expression.Prototyping.Workspace' that could not
be found. c:\users\xperator\documents\visual studio
2012\Projects\SilverlightApplication3\SilverlightApplication3\MainPage.xaml 6 21 SilverlightApplication3
and
Error 2 The type 'Workspace:InkCanvas' was not found. Verify that you
are not missing an assembly reference and that all referenced
assemblies have been built. c:\users\xperator\documents\visual studio
2012\Projects\SilverlightApplication3\SilverlightApplication3\MainPage.xaml 12 10 SilverlightApplication3
As the error says, there is no Workspace in the Prototyping namespace. I can see in the Solution explorer, there is only 2 References related to the InkCanvas:
Microsoft.Expression.Prototyping.Interactivity
microsoft.expression.prototyping.runtime
Tried to add the "Workspace" from the "Add Reference" but couldn't find it.
UPDATE :
I think actually the InkCanvas is not official ported to silverlight yet. Tried to do the same steps on a fresh pc, and I just noticed InkCanvas wasn't there in the first place. Maybe something related to Blend added the prototype control in my own PC. Still it doesn't work :(
I am open to any suggestion for alternatives to InkCanvas.
I'm trying to use the ICSharpCode.AvalonEdit.TextEditor control from the SharpDevelop 4.0 project in a WPF app that I'm building, but I can't seem to get it to work.
I checked out a copy of the source code from svn://svnmirror.sharpdevelop.net/sharpdevelop/trunk/SharpDevelop/src/Libraries/AvalonEdit at revision 4304. Then, I built the project using Visual Studio 2008 SP1, which succeeded without errors.
I then created a blank new WPF project, added the build DLL to the toolbox and dropped the TextEditor control onto the default empty window, like so:
<Window x:Class="AvalonEditTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
Title="Window1" Height="300" Width="300" >
<Grid x:Name="LayoutRoot">
<avalonedit:TextEditor Name="textEditor" />
</Grid>
</Window>
However, when I run the project, the form comes up completely blank. No caret, the mouse cursor stays the default pointer, and the window does not respond to keypresses.
Am I missing something, or is AvalonEdit just a little broken?
[EDIT: I'm starting to think it might be related to my specific setup. I'm running the 64-bit Windows 7 RC. Might that have something to do with it? I've tried building it for x86 only, made no difference.]
Are you sure your namespace declaration is correct?
You can try something like this:
<Window x:Class="Editor.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
xmlns:e="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit">
<Grid>
<e:TextEditor x:Name="Editor" WordWrap="True" Height="200">
</e:TextEditor>
</Grid>
</Window>
I was able to get it to work without any issues.
The AvalonEdit TextEditor is just a view for a TextDocument model.
The problem was that a new AvalonEdit instance didn't start connected to any model instance, so there wasn't anything to edit.
The reason the code from statictype worked was that he didn't use <avalonedit:TextEditor/>, but <avalonedit:TextEditor></avalonedit:TextEditor>. This will assign an empty string to the Text property, which caused the editor to implicitly create a new document.
But this isn't relevant with recent AvalonEdit versions anymore, the editor will now always create a new TextDocument.
This works for me with the latest build
<DockPanel LastChildFill="True">
<avalonedit:TextEditor
HorizontalAlignment="Stretch"
Name="textEditor1"
VerticalAlignment="Stretch" />
</DockPanel>