How to get started with Microsofts RibbonControlsLibrary? - c#

I'm new to WPF programming and decided to give it a shot by trying out some ribbon control libraries.
The library that looks best for now is the Microsoft RibbonControlsLibrary. You can get it on the ribbon licensing page.
So far I've started a new project, added the control to the windows, but them I'm stuck: This is the code so far:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="808" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" xmlns:my1="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary" WindowStyle="SingleBorderWindow">
<Grid>
<my1:Ribbon HorizontalAlignment="Left" Name="ribbon1" VerticalAlignment="Top" Height="165" Width="786" ShowQuickAccessToolbarOnTop="False" WindowIconVisibility="Visible" DataContext="{Binding}" Margin="0,-20,0,0">
<my1:Ribbon.ApplicationMenu>
<my1:RibbonApplicationMenu Visibility="Hidden" IsEnabled="True" />
</my1:Ribbon.ApplicationMenu>
<my1:RibbonTab Label="Tab1" Name="rtab1" >
</my1:RibbonTab>
<my1:RibbonTab Label="tab2" Name="rtab2"/>
</my1:Ribbon>
</Grid>
</Window>
Questions:
1) Where can I find samples for this ribbon control? I've tried googling, but came up with nothing useful.
2) How to add items to specific ribbon tabs? I'm lost in all these properties in the property grid. So far I havent found a designer for that purpose.
3) How can I switch the designer to show me what icons/button/... I placed on TabPage2?
(FYI: The fluent ribbon library does not seem to work for me, because I can't get rid of the ApplicationMenu.)

Found a great sample/tutorial:
http://windowsclient.net/downloads/folders/hands-on-labs/entry76491.aspx
The sample provides a manual with explanations and some test projects with step by step instructions to implement the ribbon control.
Though I'm totally new to WPF, I managed to extract necessary classes from the sample to provide a ribon based menu in my program.

Related

WPF RibbonWindow Minimize, Maximize / Restore, and Close Buttons Not Visible

So I've googled all day trying to find an answer and have come up short. I've found stuff close and maybe even found a solution and just didn't realized it but I cant seem to get the Minimize, Maximize / Restore, and Close buttons to show up (be visible) on my windows 10 machine. No one but myself and another developer who just got new laptops have this issue. I've tried changing my windows theme around and I did get them to show up with I turned some high contrast setting on but no luck otherwise. Despite not being visible they are there and functional because I can click in the area and see the window min, max, restore, close.
We are using .Net 4.0 and a RibbonWindow with a custom theme (BureauBlue.xaml). I'd like to believe it may have something to do with that but I don't know anything about it or where to start unfortunately.
<r:RibbonWindow x:Class="Ztools.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:props="clr-namespace:Ztools.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
IsTabStop="False" Icon="/Ztools;component/ztools32.ico" Height="830" Width="1200" WindowStartupLocation="CenterScreen" WindowState="Normal"
Loaded="RibbonWindow_Loaded" Closing="RibbonWindow_Closing"
xmlns:my="clr-namespace:System;assembly=mscorlib" Title="Ztools 2.0" Name="mainRibbon" FontSize="14" SizeChanged="mainRibbon_SizeChanged" LocationChanged="mainRibbon_LocationChanged"
StateChanged="mainRibbon_StateChanged" Deactivated="mainRibbon_Deactivated" KeyUp="mainRibbon_KeyUp" Background="{x:Null}">
<r:RibbonWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Ztools;component/themes/bureaublue.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</r:RibbonWindow.Resources>
</r:RibbonWindow>
Another thing I noticed but haven't verified by pulling out my old laptop yet is I'm pretty sure the nice looking buttons showed up at design time as well and didn't look like this.
Bonus question/issue is sometimes when our computers go to sleep/hibernate go from docking station to no station (not sure which one or both) the theme bar will also randomly black out like this. If I could look at fixing this at the same time that would be great.
I did change it to a normal Window and was able to see all the buttons correctly but I guess I'd rather not go that route and know what the issue is and solve it.
Any thoughts ideas or suggestions are greatly appreciated.
Edit: So I don't think it has anything to do with the theme? I commented out everything having to do with the theme and they still don't show up... Not sure why I didn't take that simple step a long time ago.
So going to post this again that way anyone with the same or similar issue can at least have an option to fixing their issue... since for some reason it was deleted despite containing valuable information as an alternative solution to the problem.
For now I changed it from a RibbonWindow to a Window an gave my Ribbon a margin of 0,-22,0,0 so things line up and look decent as suggested by a number of other SO posts. The buttons show up now, but aren't the RibbonWindow style so is what it is.
<Window x:Class="Ztools.Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:props="clr-namespace:Ztools.Properties"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
IsTabStop="False" Icon="/Ztools;component/ztools32.ico" Height="830" Width="1200" WindowStartupLocation="CenterScreen" WindowState="Normal"
Loaded="RibbonWindow_Loaded" Closing="RibbonWindow_Closing"
xmlns:my="clr-namespace:System;assembly=mscorlib" Title="Ztools 2.0" Name="mainRibbon" FontSize="14" SizeChanged="mainRibbon_SizeChanged" LocationChanged="mainRibbon_LocationChanged" StateChanged="mainRibbon_StateChanged" Deactivated="mainRibbon_Deactivated" KeyUp="mainRibbon_KeyUp">
<r:Ribbon Title="Ztools 2.0 (Scale Configuration Editor)" IsTabStop="False" Background="#FFE5E5E5" FontSize="12" FontFamily="Arial" Margin="0,-22,0,0">
</r:Ribbon>
</Window>
The ribbonwindow in version 5 has set WindowStyle="none" by default.
Maybe the WindowStyle is just set to None?
Try set it to "SingleBorderWindow" its original default in the base class.
I not only had the same issue but was able to replicate it in a new project and fix it through this solution although for you it will require moving to a more recent .net version.
The problem seems to stem from using RibbonControlsLibrary. It's is an outdated version of the ribbon controls. As of .net 4.5 Ribbon is native to the framework and by removing the reference you'll be able to use the included RibbonWindow.
Move to a .net version 4.5+ and remove this reference
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
and use
<RibbonWindow>
instead of
<r:RibbonWindow>

On Windows 10 (1803), all applications lost touch or stylus if a WPF transparent window covers on them

If I create a new WPF application with a simple empty window like the code shown below, I find that all applications which are covered by the WPF app lost touch or stylus reaction. This can only be reproduced when Windows 10 is upgraded to 1803 (10.0.17134.0).
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" Background="Transparent"
Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
I wrote another WPF application to find out what happened. So I add a StylusDown event to the Window like the code shown below:
// This code is in another WPF application.
private void OnStylusDown(object sender, StylusDownEventArgs e)
{
// Set a breakpoint here.
}
But the breakpoint never reached until I closed the transparent WPF window which is on top.
I pushed the very simple code to GitHub: dotnet-campus/TouchIssueOnWindows10.0.17134. Cloning it might help a little.
Why does this happen and how to solve it? Any reply is appreciated.
Updated
Microsoft has fixed this issue in .NET Framework August 2018 Preview of Quality Rollup.
August 30, 2018—KB4346783 (OS Build 17134.254)
Addresses an issue where touch and mouse events were handled differently in Windows Presentation Foundation (WPF) applications that have a transparent overlay window.
Original
After a whole week's debugging, I finally find out the solution.
Just add a ResizeMode="NoResize" property for the Window as the code shown below:
<Window x:Class="TheWPFCoveringWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None" WindowState="Maximized"
AllowsTransparency="True" ResizeMode="NoResize"
Background="Transparent" Topmost="True">
<Button Content="Test" Width="200" Height="100" />
</Window>
#lindexi has posted this issue and this solution into his post. If you want more information about this issue, read win10 17025 touch bug - lindexi for more details. (This post is written in multiple languages, so you'll miss nothing even if you ignore the unknown characters.)
Actually, I still can't figure out why this property helps.
Could anyone explain the reason for this issue?

Report Viewer in WPF?

I want to add a report viewer (just like crystal report viewer) in my WPF project. Here I find a link to do this. But this is done by windowsForm Control Hosting. I want to add a report viewer without hosting a winFom Control.
I believe crystal reports (SAP, actually) has a WPF version of their viewer. It can be used with the following code (as an example):
<Window x:Class="WpfCrystalReport.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=
SAPBusinessObjects.WPF.Viewer"
Title="MainWindow" Height="350" Width="525">
<Grid>
<my:CrystalReportsViewer HorizontalAlignment="Left" Name="crystalReportsViewer1"
VerticalAlignment="Top" Height="500" Width="500" />
</Grid>
</Window>
You need to be sure to reference "SAPBusinessObjects.WPF.Viewer.dll" and also reference "SAPBusinessObjects.WPF.ViewerShared.dll". I am guessing that these are normally downloaded with the crystal reports development version.
Note - If you need a full tutorial, as of this answer, you can find more information at C-Sharp Corner here. The second page of the article is where they actually create the report and add it to the form.

Developing Custom Window into Class Library in WPF

I'm trying to develop Custom Window, which i can reuse in other applications.
I know that WPF cannot derive from XAML
I also tried to deploy it as Class Library, the code provided in this
video:
http://www.youtube.com/watch?v=EuhhL_NF-B0&feature=c4-overview&list=UUjwAVugYBMQemsMi9AD4SZA
, but still it does not read the XAML file.
I tried with code-behind to set the ControlTemplate, but as i read FrameworkElementFactory is deprecated...
All i want to do is, derive from Window, change the ControlTemplate, release it as Class Library... anyone can show me how or point me to the right direction?
In my opinion the best solution will be to create custom UserControl, and then load it from Window.xaml.
Once you created your user control just load it from Window like this:
<Window xmlns:my="clr-namespace:Styx.GUI.View" x:Class="Styx.GUI.View.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="800" Width="650" MinHeight="600" MinWidth="600">
<my:MainWindowUserControl />
</Window>

Using ICSharpCode.AvalonEdit on .Net 3.5?

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>

Categories

Resources