I have this code to set up toolbar items in XAML.
<ContentPage.ToolbarItems>
<ToolbarItem Name="Menu1" Activated="OnClick" Order="Primary" Priority="{StaticResource Priority1}" />
<ToolbarItem Name="Menu2" Activated="OnClick" Order="Secondary" Priority="{StaticResource Priority2}" />
</ContentPage.ToolbarItems>
The rendering is fine in Android , but in WPF I see an ugly square icon (is a placeholder for a missing icon?)
Any ideas?
WPF render example
Android render example
Try adding an icon for the Toolbaritem in the Assets folder.
Also, try updating the Xamarin.Forms version - with version 3.3.0.967583 I can not observe placeholder icons.
Please note that the Name and Activated properties are obsolete - use Text and Clicked, respectively:
<ToolbarItem Text="Menu1"
Icon="{OnPlatform WPF=Assets/menu1.png}"
Order="Primary"
Clicked="OnToolbarItemClicked" />
<ToolbarItem Text="Menu2"
Icon="{OnPlatform WPF=Assets/menu2.png}"
Order="Secondary"
Clicked="OnToolbarItemClicked" />
Related
I'm implementing a custom simplified editor in WPF using AvalonEdit and MahApps.Metro. I am stuck trying to get the cut/copy/paste/undo/redo commands working using MahApps.Metro icon/circle buttons instead of a toolbar.
The AvalonEdit sample uses a toolbar, and if I add a similar toolbar to my current application, it works as expected.
I want to call the Cut/Copy/Paste from a series of icon buttons on my app layout instead of inside a toolbar. My MahApps.Metro buttons are as follows. I've tried it with and without the Command Target set. In both cases nothing happens when I click them.
<Button Width="48"
Height="48"
Margin="24,0,0,0"
Style="{DynamicResource MahApps.Metro.Styles.MetroCircleButtonStyle}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Command="Undo"
CommandTarget="{Binding ElementName=xmlTextEditor.TextArea}">
<iconPacks:PackIconMaterial Kind="UndoVariant" />
</Button>
I'm relatively new to WPF so I might be missing something really basic here. Any help is appreciated.
I am using WPF Interoperability (ElementHost) to display a XAML control in WinForms. This works perfectly for my needs as I must use WinForms for a project I am working on. The issue is that when I add images, such as icons, to the Ribbon in XAML, I can no longer add the XAML Ribbon to the WinForm. The error I keep getting is:
An error occurred trying to create an object of type 'WPF.Ribbon'. Make sure the type has a default constructor.
The images have a Build Action of "Resource". Here is an example XAML code snippet I am using for my ribbon code:
<RibbonButton SmallImageSource="/App/Images/Ribbon/cut.png" Label="Cut" KeyTip="X" />
When I remove the image source, I can compile the code fine, and the ribbon displays without any issue.
The resolution is to add absolute addresses, such as:
<RibbonButton SmallImageSource = "C:\Path To Images\App\Images\Ribbon\cut.png" Label="Cut" KeyTip="X" />
I'm using Elysium in my wpf application to get a metro styled interface. However the style is not preserved when I try to use Windows forms control.
Example:
<Grid>
<RichTextBox />
</Grid>
Gives a perfect result (with the thin white border around the wpf control)
However:
xmlns:WinForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
.
.
<Grid>
<WindowsFormsHost Name="wfh">
<WinForms:RichTextBox />
</WindowsFormsHost>
</Grid>
Gives me a different look with the legacy windows form type of border.
I want the thin white border around my WindowsFormElement if possible. I'm out of ideas at the moment.
I have a WinForm application in which I am trying to replace my toolbar with a WPF toolbar.
My solution now contains two projects:
A WPF user control project that defines the WPF toolbar
A Windows Form Application that hosts the WPF toolbar
Enabling / disabling buttons, adding items to combos, events handling of toolbar controls will have to be defined in the WinForm application, so in order to have access to them, I did the following:
in the XAML I gave each control in the toolbar a name
In the code I defined a public get property for each control
This works fine, but I was wondering if this is the right approach. Is there a better way to do what I want?
Can you post the XAML of your toolbar? – HighCore
I've made a small example of the XAML of my toolbar as you asked.
<ToolBarTray>
<ToolBar Band="1" BandIndex="1">
<Button Name="btnDoSomething1">
<Image Source="/WpfExampToolbarCtrl;component/Images/DoSomething1.png" />
</Button>
<Button Name="btnDoSomething2">
<Image Source="/WpfExampToolbarCtrl;component/Images/DoSomething2.png" />
</Button>
<Separator />
<Menu>
<MenuItem Header="Create Item">
<MenuItem Header="Item 1" />
<MenuItem Header="Item 2" />
</MenuItem>
</Menu>
<Separator />
<ComboBox Name="comboCategory">
<ComboBoxItem Content="Category 1" IsSelected="True" />
<ComboBoxItem Content="Category 2" />
</ComboBox>
</ToolBar>
</ToolBarTray>
I thought to give each control in the toolbar a name, and in the code behind define a get property for each one. This way I could access each of the toolbar's controls from my the main form of my WinForm application, and do what I want. (Add events, disable/enable controls at runtime, add items to combos at initialization or during runtime, …).
But from what I understand from Kent Boogaart answer this is not the right approach.
I'd sooner have my WPF UI bound to a model. I would then access the model from the Winforms side and manipulate that.
To elaborate: WPF's binding infrastructure is very strong and unlike what you're used to in Winforms. WPF applications tend to follow the MVVM pattern, whereby the view's data context is a view model, and your controls in the view have bindings against properties in your view model.
Thus, what I'm suggesting is you first define a view model, then modify your WPF view to bind to properties on that view model, then access that view model from your Winforms code. Changing properties on that view model from your Winforms code will automatically update the WPF view.
According to the MSDN documentation, a ribbon:RibbonControlSizeDefinition can be used to control the size of an item on a WPF ribbon by setting the ControlSizeDefinition property. Has anyone had any success using this property? I find that it is completely ignored. I initially set it using data binding, but have also tried using the code behind file.
This question is similar, but it is correctly noted in one of the comments that the OP had used a RibbonControlGroup, and therefore was seeing the expected behaviour.
I understand that it's usually best to allow the ribbon to do it's own thing regarding sizing. Sadly that's not an option for this project.
I've listed the part of my XAML code that doesn't work below.
<ribbon:RibbonTab Header="MyTab">
<ribbon:RibbonGroup Header="MyGroup">
<ribbon:RibbonButton Label="My big button" Name="BigButton"
LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png"
SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True" />
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
<ribbon:RibbonButton Label="My little button" Name="SmallButton"
LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png"
SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True" />
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
</ribbon:RibbonGroup>
</ribbon:RibbonTab>
After some experimentation, I have a workaround. I tried using group-level sizing instead of item-level sizing, using the ribbon:RibbonGroup.GroupSizeDefinitions property. This works as documented. Additionally, setting this to an empty RibbonGroupSizeDefinition is enough to make the item-level properties work. My code from above becomes:
<ribbon:RibbonTab Header="MyTab">
<ribbon:RibbonGroup Header="MyGroup">
<ribbon:RibbonGroup.GroupSizeDefinitions>
<ribbon:RibbonGroupSizeDefinition>
</ribbon:RibbonGroupSizeDefinition>
</ribbon:RibbonGroup.GroupSizeDefinitions>
<ribbon:RibbonButton Label="My big button" Name="BigButton" LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png" SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True" />
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
<ribbon:RibbonButton Label="My little button" Name="SmallButton" LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png" SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True" />
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
</ribbon:RibbonGroup>
</ribbon:RibbonTab>