How to start using Ribbons in WPF - wpf

I tried referencing the System.Windows.Controls.Ribbon, the toolbox tab does not show up. If I right-click a tab and click show all, the tab is there, but controls aren't light up. I can add a tab and controls related manually, but after adding the ribbon, things like quickaccesstoolbar and menuitem does not work properly - they are being treated as tabs for some reason. Control groups don't work as well. Simply nothing works as it's supposed to.
I have tried editing XAML directly. It fails in the same manner as using the designer.
The tutorials online are either outdated, for a paid control suite, or simply don't work.
I don't want to use mark-up solutions like http://www.codeproject.com/Articles/364272/Easily-Add-a-Ribbon-into-a-WinForms-Application-Cs , I want something that works in a designer -- Is that too much to ask? If so I'll gladly go back to winforms.
If you work with ribbons, how did you do it? This question seems simple, but after digging for hours I still don't have an answer.
I'm an individual developer, making an open source, free software. As a student I really can't afford 1000$ control suites. I use VS2013 community, I tried using 2015 instead, but all the problems above are the same.

Add this reference:
and this namespace in the XAML file:
and try working with this code example:
<DockPanel>
<Ribbon DockPanel.Dock="Top" Margin="0,-22,0,0">
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu SmallImageSource="Images/list.png">
<RibbonApplicationMenu.AuxiliaryPaneContent>
<RibbonGallery ScrollViewer.VerticalScrollBarVisibility="Auto">
<RibbonGalleryCategory MaxColumnCount="1">
<RibbonGalleryItem
x:Name="GalleryItem1" Content="Application menu content"
MouseOverBackground="Transparent"
MouseOverBorderBrush="Transparent"
CheckedBackground="Transparent"
CheckedBorderBrush="Transparent"
/>
<RibbonGalleryItem>
<Hyperlink x:Name="hl1" Click="hl1_Click">
<Run Text="http://www.bing.com"/>
</Hyperlink>
</RibbonGalleryItem>
</RibbonGalleryCategory>
</RibbonGallery>
</RibbonApplicationMenu.AuxiliaryPaneContent>
<RibbonApplicationMenuItem x:Name="menuItem1" Header="Add"
ImageSource="Images/add.png"/>
<RibbonApplicationMenuItem x:Name="menuItem2" Header="Settings"
ImageSource="Images/system_preferences.png"/>
<RibbonApplicationMenu>
</Ribbon.ApplicationMenu>
<RibbonTab x:Name="rbnTab1" Header="Tab1">
<RibbonGroup x:Name="rbnGr1" Header="General">
<RibbonButton x:Name="btnRibbon1" Label="Save"
LargeImageSource="Images/filesave.png"/>
<RibbonButton x:Name="btnRibbon2" Label="Open"
LargeImageSource="Images/load.png"/>
</RibbonGroup>
<RibbonGroup x:Name="rbnGr2" Header="New group">
<RibbonButton x:Name="btnRibbon3" Label="Font"
LargeImageSource="Images/fonts.png"/>
<RibbonButton x:Name="btnRibbon4" Label="Delete"
LargeImageSource="Images/recycle_bin.png"/>
</RibbonGroup>
</RibbonTab>
<RibbonTab x:Name="rbnTab2" Header="Tab2">
<RibbonGroup x:Name="rbnGr3" Header="Other Group">
<RibbonButton x:Name="btnRibbon5" Label="Play"
LargeImageSource="Images/play.png"/>
<RibbonButton x:Name="btnRibbon6" Label="List"
LargeImageSource="Images/kmenuedit.png"/>
</RibbonGroup>
<RibbonGroup x:Name="rbnGr4" Header="What a group">
<RibbonButton x:Name="btnRibbon7" Label="Sleep"
LargeImageSource="Images/icon_sleep.png"/>
<RibbonButton x:Name="btnRibbon8" Label="Add"
LargeImageSource="Images/add.png"/>
</RibbonGroup>
</RibbonTab>
</Ribbon>
<Grid>
<!-- add your content here-->
</Grid>
</DockPanel>
You can remove the <Ribbon.ApplicationMenu> if you don't like it by addin this property Visibility="Collapsed"
<Ribbon.ApplicationMenu>
<RibbonApplicationMenu Visibility="Collapsed">
</RibbonApplicationMenu>
</Ribbon.ApplicationMenu>

Please take a look at the following. You should be able to have a very basic idea about Ribbon.
http://blogs.msdn.com/b/wpf/archive/2010/08/03/introducing-microsoft-ribbon-for-wpf.aspx
Sample project download
If you want to run the project, you need to change the project's .NET Framework version to 4.0 or above.
Add System.Window.Controls.Ribbon reference to the project
Remove reference like System.Window.Shell and RibbonControlLibrary
The sample should be able to run after you fixed all the namespaces in xmal and the codebehind .cs
http://blogs.msdn.com/b/wpf/archive/2010/08/03/building-a-simple-ribbon-application-in-wpf.aspx
Microsoft Ribbon for WPF (Get the one with Sample for more comprehensive sample)
http://www.microsoft.com/en-us/download/details.aspx?id=11877

Related

How can I make a multi panel on-screen keyboard? (XAML)

We have an Intermec touchscreen terminal (OS: Win7).
We use an application on it that uses an on-screen keyboard stored in xaml files (VTFKey, VTKey, VTKeyCaps, VTKeyShifted, VTKeyShiftedCaps).
I pasted the code from VTKey.xaml for the buttons that toggle between keyboard panels (the xaml files mentioned above):
<Button Canvas.Top="105.545" Height="49.995" Width="125" Command="{Binding Path=PressAndRelease}" CommandParameter="VK_CAPITAL" Content="Cap" />
<Button Canvas.Left="724" Canvas.Top="208.692" Height="50" Width="90" Command="{Binding Path=PressAndRelease}" CommandParameter="VK_TOGGLE" Content="Toggle" />
<Button Style="{DynamicResource ShiftKey}" Canvas.Left="836.583" Canvas.Top="156.651" Height="50" Width="163.317" Command="{Binding Path=PressAndHold}" CommandParameter="RSHIFT" Content="Shift" />
My question would be how do these commands (VK_CAPITAL, VK_TOGGLE, RSHIFT) know which xaml file to change to?
How could I create a custom keyboard consisting of 6 customized panels(xaml files)? Is it even possible?
Thank you!
My question would be how do these commands (VK_CAPITAL, VK_TOGGLE, RSHIFT) know which xaml file to change to?
You have XAML for the following three Buttons:
<Button Canvas.Top="105.545" Height="49.995" Width="125"
Command="{Binding Path=PressAndRelease}" CommandParameter="VK_CAPITAL"
Content="Cap" />
<Button Canvas.Left="724" Canvas.Top="208.692" Height="50" Width="90"
Command="{Binding Path=PressAndRelease}" CommandParameter="VK_TOGGLE"
Content="Toggle" />
<Button Style="{DynamicResource ShiftKey}" Height="50" Width="163.317"
Command="{Binding Path=PressAndHold}" CommandParameter="RSHIFT"
Content="Shift" />
Note the Command property... this is the name of the ICommand instance that performs the functionality for each Button. Two of these Buttons use the PressAndRelease Command. In this case, the CommandParameter is also used... inside the PressAndRelease Command code, you would probably see something like this:
if (parameter == "VK_CAPITAL") LoadVkCapitalView();
...
else if (parameter == "VK_TOGGLE") LoadVkToggleView();
As for the last part of your question, you'll have ask a more precise question for me to be able to answer it.

Navigating to a different assembly in Silverlight

I'm trying to navigate to a page located in a different assembly with no success.
I made an extremely simple Silverlight Navigation Application make my point:
I simply have a Hyperlink with:
NavigateUri="/PageClassLibrary;component/Pages/PageInLibrary.xaml"
In the calling page (MainPage.xaml in MainNavigationApp) I have a Frame with no UriMappings for now.
<Grid x:Name="LayoutRoot">
<navigation:Frame x:Name="ContentFrame"
Style="{StaticResource ContentFrameStyle}"
Navigated="ContentFrame_Navigated"
NavigationFailed="ContentFrame_NavigationFailed">
</navigation:Frame>
<Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}">
<StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}">
<HyperlinkButton x:Name="Link3"
Style="{StaticResource LinkStyle}"
NavigateUri="/PageClassLibrary;component/Pages/PageInLibrary.xaml"
TargetName="ContentFrame"
Content="page in a class library" />
</StackPanel>
</Grid>
</Grid>
But when I run it, I get an error message saying that the page was not found:
Page not found: "/PageClassLibrary;component/Pages/PageInLibrary.xaml"
I even modified MainNavigationApp dependencies, checking depends on PageClassLibrary, but it didn't improve the outcome.
I ran out of ideas. Does anybody have a hint?
Here's thesolution:
https://skydrive.live.com/#cid=B79120F33F3A7A64&id=B79120F33F3A7A64%21105
AAAhhh!, the solution was there in front of my eyes. JUST ADD A REFERENCE TO THE ASSEMBLY. dah!

Dialog form in wpf change content

I want to display a dialog form for new and edit actions... However title, buttons , and few other things should change.
I am wondering how i could implement this. Provide an enum value at constructor ? Like Mode.New or Mode.Edit ? Is there a way to avoid writing code like spNewButtons.Visibillity=Collapsed .. etc , and put it inside wpf ?
You can bind visibility with your mode property, and create a specific IValueConverter to convert the mode to a proper Visibility value. ie:
<StakPanel Visibility={Binding Mode,Converter={StaticResource myProperConverter}}></StackPanel>
Usually my WPF dialogs are all ContentControls that get displayed in a Popup.
My code usually looks like this:
<Grid Name="RootPanel">
<!-- Other Content -->
<!-- Popup is always last so it gets displayed on top of other contnet -->
<local:PopupPanel
local:PopupPanel.PopupParent="{Binding ElementName=RootPanel}"
local:PopupPanel.IsPopupVisible="{Binding IsPopupVisible}"
local:PopupPanel.PopupEnterKeyCommand="{Binding SaveCommand}"
local:PopupPanel.PopupEscapeKeyCommand="{Binding CancelCommand}">
<DockPanel>
<!-- Header -->
<Label DockPanel.Dock="Top" Content="{Binding PopupHeader}" />
<!-- Buttons -->
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Save" Command="{Binding PopupSaveCommand}" />
<Button Content="Cancel" Command="{Binding PopupCancelCommand}" />
</StackPanel>
<!-- Actual content displayed is determined by DataTemplates -->
<ContentControl Content="{Binding PopupContent}" />
</DockPanel>
</local:PopupPanel>
</Grid>
I removed a lot of the styles to make this easier to read, but you can see the general idea of how it's put together. My ViewModel usually contains properties for IsPopupVisible, PopupContent, and PopupHeader, and commands for PopupSaveCommand and PopupCancelCommand
I use my own custom popup in most cases, although the same thing could be done with a WPF popup.

wpf ribboncontrol QAT

When using Ribboncontrol october 2010 release from Microsoft, even if I don't use QAT I get a right click event "show quick access toolbar" (which doesn't do anything). How can this be disabled ?
Unfortunately the following does not do the task:
<r:Ribbon x:Name="Ribbon"
Title="title" IsMinimized="False">
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu Visibility="Collapsed"/>
</r:Ribbon.ApplicationMenu>
<r:Ribbon.QuickAccessToolBar>
<r:RibbonQuickAccessToolBar Visibility="Collapsed" />
</r:Ribbon.QuickAccessToolBar>
...
Take care that the context-menu also does not disapear, when you have disabled all other features of the ribbon.
Sorry, I thought I solved the problem some time ago, but actually I didn't.

WPF/XAML: Typography.Capitals seems to have no effect

All of these bits of text look the same, but I am trying to get them to look different. I want small caps text. What am I missing here to get the small caps typography effect to work?
To reproduce this, open Visual Studio 2008, Do File|New Project, create a new Windows|WPF application, paste the mark-up below into Window1.xaml, then run it.
<Window x:Class="WpfApplication1.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">
<Grid>
<FlowDocumentReader>
<FlowDocument>
<Paragraph>
<Run>Some text</Run> <LineBreak />
<Run Typography.Capitals="SmallCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="AllSmallCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="PetiteCaps">Some text</Run> <LineBreak />
<Run Typography.Capitals="AllPetiteCaps">Some text</Run> <LineBreak />
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</Grid>
</Window>
Based on the first answer, it seems that if you specify a particular font, you can get somewhere. Change the FlowDocument start tag to:
<FlowDocument FontFamily="Palatino Linotype">
.. and you get SmallCaps and AllSmallCaps, but not PetiteCaps or AllPetiteCaps. So it depends on the font. But this gives rise to other questions:
Why doesn't the default font (which looks a lot like Times New Roman) support these?
Do other widely used fonts (e.g. the local Courier New equivalent) support these?
Is there a list of which fonts support what?
What percentage of fonts will support this - most, some, or few?
Can you determine in code what the font supports - if this is the case, I could fake the AllSmallCaps - e.g. by converting the text to all capitals and scaling by 80%. But not SmallCaps.
This only works with specific OpenType fonts - the example in Help uses Pescadero which is in the Open Type Sample. Even then, only SmallCaps and AllSmallCaps are supported.
I noticed that default font with a "bold" fontweight does render the SmallCaps properly:
<StackPanel>
<TextBlock Typography.Capitals="SmallCaps" FontFamily="Pescadero" Padding="2">2pm</TextBlock>
<TextBlock Typography.Capitals="SmallCaps" FontWeight="Bold" Padding="2">2pm</TextBlock>
</StackPanel>

Resources