mahapps metro tabcontrol as prism region style - wpf

I have problem with prism and mahapps.metro library. I set TabControl as my region in my Shell and here i have problem beacouse every tabitem(module) not react on Triggers for example: Property="IsMouseOver". Headers have the same style and i dont know how to force them to work properly. Here is my code:
Shell.xaml
<Window.Resources>
<Style BasedOn="{StaticResource {x:Type TabItem}}" TargetType="TabItem" x:Key="HeaderStyle">
<Setter Property="Header"
Value="{Binding RelativeSource={RelativeSource Self},
Path=Content.DataContext.TabModel.Title}" />
</Style>
</Window.Resources>
<TabControl Grid.Row="1" cal:RegionManager.RegionName="{x:Static inf:RegionNames.TabContainer}" Style="{StaticResource MetroTabControl}"/>
And module:
<TabItem x:Class="DataConverter.Modules.Export.Views.MenuView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" Style="{StaticResource {x:Type TabItem}}"
Header="Export"
IsSelected="{Binding Path=IsSelected}">
when i remove Style="{StaticResource {x:Type TabItem}}" my tabitem looks like standard control. How to resolve this?

Related

Dev Express Grid control cell style not applied WPF

I tried to set the cell style for the grid control column within Lookupedit. but not applied at run time, but if I remove any property of the grid control column in debug mode at the time style applied, cell style should be applied when binding the data source, any idea to fix this, below is the code snippet
Thanks in advance,
Pandiyan Thangarasu
<UserControl x:Class="VisualizeWorkFlow.Legends"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
xmlns:local="clr-namespace:VisualizeWorkFlow"
mc:Ignorable="d"
BorderBrush="LightGray">
<UserControl.Resources>
<local:LegendColorCodeConverterClass x:Key="LegendColorCodeConverter"/>
</UserControl.Resources>
<Grid Background="White">
<dxg:LookUpEdit DisplayMember="Name" dxc:ThemeManager.ThemeName="Office2010Silver" Name="PART_Editor" Width="300" >
<dxg:LookUpEdit.PopupContentTemplate>
<ControlTemplate>
<dxg:GridControl Name="PART_GridControl" CustomColumnDisplayText="PART_GridControl_CustomColumnDisplayText">
<dxg:GridControl.Columns>
<dxg:GridColumn Header="Name" Width="150" FieldName="Name" />
<dxg:GridColumn Header="Color Code" Width="30" FieldName="ColorCode">
<dxg:GridColumn.CellStyle>
<Style BasedOn="{StaticResource {dxgt:GridRowThemeKey ResourceKey=CellStyle}}" TargetType="dxg:CellContentPresenter">
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="Background" Value="{Binding Value, Converter={StaticResource LegendColorCodeConverter}}"/>
</Style>
</dxg:GridColumn.CellStyle>
</dxg:GridColumn>
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TreeListView KeyFieldName="ID" ParentFieldName="ParentID" ShowColumnHeaders="False" ShowIndicator="False" AutoExpandAllNodes="True"/>
</dxg:GridControl.View>
</dxg:GridControl>
</ControlTemplate>
</dxg:LookUpEdit.PopupContentTemplate>
</dxg:LookUpEdit>
</Grid>
</UserControl>

WPF XAML x:Type is underlined and states "MyColor" does not exist in the namespace .... Why?

I'm trying to display on a DataGrid a ObservableCollection. For each item in the ObservableCollection, I have a ComboBox that displays the currently selected item (MyColor in my example) and lets the user choose a different color from the combobox. This was working reasonably well when my Enum MyColor was in the same namespace as the MainWindow. However, to make the example closer to the problem I'm actually trying to solve I put the MyColor enum in a different project and namespace. I've included all code. In the XAML for the mainwindow, I have a ObjectDataProvider and the line
<x:Type TypeName="enu:MyColor" />
The word x:Type is underlined and has the message: The name MyColor does not exist in the namespace "clr-namespace:Library.EnumDefinitions;assembly=Library.EnumDefinitions"
I've double and triple checked spelling, but don't see the problem. MyColor is defined in the namespace Library.EnumDefinitions. I'm wondering if the fact that the enum is in a separate namespace and project is causing me grief. The idea of using ObjectDataProvider can by found here for example:
https://brianlagunas.com/a-better-way-to-data-bind-enums-in-wpf/
The suggestion that there might be something special going on if your enum is in a different project/namespace is given here:
The name does not exist in the namespace in WPF application
I do have a reference to the different project in my Main project.
Any idea what is going on? If I can provide other information, please let me know.
Thanks,
Dave
MainWindow XAML
<Window x:Class="TrickyBindingProblems.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:enu="clr-namespace:Library.EnumDefinitions;assembly=Library.EnumDefinitions"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ObjectDataProvider x:Key="EnumDataProvider" MethodName="GetValues"
ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="enu:MyColor" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<DataGrid Grid.Column="1"
Margin="0"
HorizontalAlignment="Left"
AutoGenerateColumns="False"
Background="Transparent"
DataContext="{Binding}"
HeadersVisibility="Column"
ItemsSource="{Binding Cars}"
SelectedItem="{Binding SelectedItemProperty, Mode=TwoWay}"
RowBackground="Transparent"
RowHeight="30">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="BorderBrush" Value="{x:Null}" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontWeight" Value="Bold" />
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTemplateColumn Width="*" Header="Make">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center"
Padding="5"
Text="{Binding Make}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="*" Header="Color (as ComboBox)">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource EnumDataProvider}}" SelectedItem="{Binding Color, Mode=TwoWay}">
<ComboBox.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Black" />
</Style>
</ComboBox.Resources>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
namespace Library.EnumDefinitions
{
public enum MyColor
{
Red,
Blue,
Green
}
}
UPDATE!!!
I believe I fixed my immediate problem. I changed the line:
xmlns:enu="clr-namespace:Library.EnumDefinitions;assembly=Library.EnumDefinitions"
to:
xmlns:enu="clr-namespace:Library.EnumDefinitions"
Can someone tell me when you are suppose to use the "assembly" part and when you are not?

Split TabItem cause style lost

I've a TabControl with this structure:
<TabControl>
<TabControl.Resources>
<Style TargetType="TabItem" BasedOn="{StaticResource MetroTabItem}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="20" />
</Style>
</TabControl.Resources>
<local:Analysis />
</TabControl>
Now I need to split each TabItem, so I've create something like a UserControl with this structure:
<TabItem xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d" Header="Analysis" Style="{StaticResource MetroTabItem}">
<Grid>
</Grid>
the problem's that the TabItem imported with namespace local: doesn't take the style of the TabControl in the Resource.
So for solve this I need to put the style resource in each TabItem, this will cause redundancy code.
How can I take the style of TabControl Resource in the splitted TabItem?
Thanks.
You can create your own style as a static resource in your App.xaml or your Window.xaml like this:
<Application.Resources>
<Style TargetType="TabItem" x:Key="MyTabItemStyle" BasedOn="{StaticResource MetroTabItem}">
<Setter Property="Controls:ControlsHelper.HeaderFontSize" Value="20" />
</Style>
</Application.Resources>
You give your style a name (MyTabItemStyle in this example) which is based on the MetroTabItem style.
Then, instead of using the MetroTabItem style directly in your custom TabItem, you use your own style MyTabItemStyle like this:
<TabItem xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
mc:Ignorable="d" Header="Analysis" Style="{StaticResource MyTabItemStyle}">
<Grid>
</Grid>
</TabItem>

Prism 4/Silverlight 4/MEF - Region not found

I'm just learning PRISM so may be this is very simple error: I'm trying to define Region in 'Style' and they not found :( :(
On main 'Shell' window I have 'ContentControl' that include 'Frame' object. The 'ContentControl' styled in attached ResourceDictionary and all Regions defined there (with additional Colors, Brushes, Buttons, Grids, etc...) But whenever program runs (all correctly shown on screen) the IRegionManager.Regions is empty collection....
Is there anything I can do to use regions from 'Style' ???
This is the code:
Shell.xaml
<UserControl x:Class="CardManagment.Shell"
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
<ContentControl HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Style="{StaticResource MainWindowStyle}">
<sdk:Frame x:Name="MainFrame"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="#FFFB0000"
Style="{StaticResource GlobalNavigationFrameStyle}"
UriMapper="{StaticResource GlobalUriMapper}" />
</ContentControl>
</UserControl>
and ResourceDictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="clr-namespace:Microsoft.Practices.Prism.Regions;assembly=Microsoft.Practices.Prism"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit">
<Style x:Key="MainWindowStyle" TargetType="ContentControl">
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
...
...
...
<Border Grid.Row="1" BorderThickness="2" CornerRadius="2" BorderBrush="#FFDC1EBA">
<ContentControl x:Name="GlobalLogoRegion" prism:RegionManager.RegionName="GlobalLogoRegion" />
</Border>
...
...
Ok - for now I found an answer on this page: Regions inside DataTemplates in Prism v4 using a region behavior
Actually it's a known bug in PRISM according to this article.

WPF custom control style problem

I have a custom control (from MS Toolkit - DatePicker). I've made my own style like this:
<Style TargetType="{x:Type local:DatePicker}">
But this style does not apply automatically. I have to add Key:
<Style x:Key="DatePickerStyle" TargetType="{x:Type local:DatePicker}">
and reference it in each custom control like
<toolkit:DatePicker Style="{StaticResource DatePickerStyle}"
...
to get it working. Does anyone know why?
have you tried changing the TargetType to:
TargetType="{x:Type toolkit:DatePicker}">
You are referencing local in one place and toolkit in another.
update:
I've tried it in a small app. This is the xaml as it should work:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication3.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480"
xmlns:Toolkit="http://schemas.microsoft.com/wpf/2008/toolkit">
<Window.Resources>
<Style TargetType="{x:Type Toolkit:DatePicker}">
<Setter Property="Background" Value="#FFFF0000"/>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Toolkit:DatePicker HorizontalAlignment="Left"
Margin="61,143,0,116" Width="232" />
</Grid>
</Window>
This example should create a datepicker with a red background.

Resources