I am just trying to apply a theme in a mvvm wpf caliburn.micro app. I added references for the necessary no-xaml wpf binaries (Telerik.Windows.Controls/Navigation, Telerik.Windows.Data (Binaries.NoXAML), in addition I added a reference to the required theme (Telerik.Windows.Themes.Green) and added the resources in a merged resource dictionary in my app.xaml.
I still can't get theming to work. Using implicit styled controls, I can't see any data displayed, but not using implicit styles everything is ok!
1) what am I missing?
2) And where should I apply e.g. : GreenPalette.LoadPreset(GreenPalette.ColorVariation.Dark) - in my bottstrapper?;
Thanks for your help.
Oliver
app.xaml
01.
<
Application
x:Class
=
"Notizen.App"
xmlns
=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
=
"http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local
=
"clr-namespace:Notizen"
>
02.
<
Application.Resources
>
03.
<
ResourceDictionary
>
04.
<
ResourceDictionary.MergedDictionaries
>
09.
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.xaml"
/>
10.
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>-->
11.
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Green;component/Themes/System.Windows.xaml"
/>
12.
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.xaml"
/>
13.
<
ResourceDictionary
Source
=
"/Telerik.Windows.Themes.Green;component/Themes/Telerik.Windows.Controls.Navigation.xaml"
/>
14.
<
ResourceDictionary
>
15.
<
local:AppBootstrapper
x:Key
=
"bootstrapper"
/>
16.
</
ResourceDictionary
>
17.
</
ResourceDictionary.MergedDictionaries
>
18.
</
ResourceDictionary
>
19.
</
Application.Resources
>
20.
</
Application
>
appbootsrapper.cs
01.
namespace
Notizen {
02.
using
System;
03.
using
System.Collections.Generic;
04.
using
Caliburn.Micro;
05.
using
System.ComponentModel.Composition.Hosting;
06.
using
System.Linq;
07.
using
System.ComponentModel.Composition;
08.
using
System.Windows;
09.
using
Telerik.Windows.Controls;
10.
public
class
AppBootstrapper : BootstrapperBase {
11.
12.
private
CompositionContainer container;
13.
14.
public
AppBootstrapper()
15.
{
16.
Initialize();
17.
}
18.
19.
protected
override
void
Configure()
20.
{
21.
container =
new
CompositionContainer(
22.
new
AggregateCatalog(AssemblySource.Instance.Select(x =>
new
AssemblyCatalog(x)))
23.
);
24.
25.
var batch =
new
CompositionBatch();
26.
27.
batch.AddExportedValue<IWindowManager>(
new
WindowManager());
28.
//batch.AddExportedValue<IWindowManager>(new TelerikWindowManager());
29.
batch.AddExportedValue<IEventAggregator>(
new
EventAggregator());
30.
batch.AddExportedValue(container);
31.
32.
// This is essential to enable Telerik's conventions
33.
TelerikExtensions.TelerikConventions.Install();
34.
35.
GreenPalette.LoadPreset(GreenPalette.ColorVariation.Dark);
36.
//StyleManager.ApplicationTheme = ThemeManager.FromName("Expression_Dark");
37.
38.
container.Compose(batch);
39.
}
40.
41.
protected
override
object
GetInstance(Type serviceType,
string
key)
42.
{
43.
string
contract =
string
.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
44.
var exports = container.GetExportedValues<
object
>(contract);
45.
46.
if
(exports.Any())
47.
return
exports.First();
48.
49.
throw
new
Exception(
string
.Format(
"Could not locate any instances of contract {0}."
, contract));
50.
}
51.
52.
protected
override
IEnumerable<
object
> GetAllInstances(Type serviceType)
53.
{
54.
return
container.GetExportedValues<
object
>(AttributedModelServices.GetContractName(serviceType));
55.
}
56.
57.
protected
override
void
BuildUp(
object
instance)
58.
{
59.
container.SatisfyImportsOnce(instance);
60.
}
61.
62.
protected
override
void
OnStartup(
object
sender, StartupEventArgs e)
63.
{
64.
DisplayRootViewFor<IShell>();
65.
}
66.
67.
}
68.
}
tagsView.xaml
01.
<
UserControl
x:Class
=
"Notizen.Views.TagsView"
03.
xmlns:x
=
"http://schemas.microsoft.com/winfx/2006/xaml"
04.
xmlns:mc
=
"http://schemas.openxmlformats.org/markup-compatibility/2006"
05.
xmlns:d
=
"http://schemas.microsoft.com/expression/blend/2008"
06.
xmlns:local
=
"clr-namespace:Notizen.Views"
07.
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
08.
xmlns:vm
=
"clr-namespace:Notizen.ViewModels"
09.
mc:Ignorable
=
"d"
10.
d:DesignHeight
=
"300"
d:DesignWidth
=
"300"
>
11.
<
UserControl.Resources
>
12.
13.
<
Style
x:Key
=
"radTreeViewItemStyle"
TargetType
=
"{x:Type telerik:RadTreeViewItem}"
>
14.
<
Setter
Property
=
"IsExpanded"
Value
=
"{Binding IsExpanded, Mode=TwoWay}"
/>
15.
<
Setter
Property
=
"IsSelected"
Value
=
"{Binding IsSelected, Mode=TwoWay}"
/>
16.
<
Setter
Property
=
"FontWeight"
Value
=
"Normal"
/>
17.
<
Style.Triggers
>
18.
<
Trigger
Property
=
"IsSelected"
Value
=
"True"
>
19.
<
Setter
Property
=
"FontWeight"
Value
=
"Bold"
/>
20.
</
Trigger
>
21.
</
Style.Triggers
>
22.
</
Style
>
23.
24.
<
HierarchicalDataTemplate
x:Key
=
"hierarchicalDataTemplate"
25.
DataType
=
"{x:Type vm:TagViewModel}"
26.
ItemsSource
=
"{Binding Tags}"
>
27.
<
DockPanel
LastChildFill
=
"True"
>
28.
<
StackPanel
DockPanel.Dock
=
"Right"
Orientation
=
"Horizontal"
HorizontalAlignment
=
"Right"
>
29.
<
TextBlock
Text
=
"{Binding Count}"
Padding
=
"0,0,5,0"
Foreground
=
"Gray"
/>
30.
</
StackPanel
>
31.
<
StackPanel
DockPanel.Dock
=
"Left"
Orientation
=
"Horizontal"
>
32.
33.
<!--<Image Width="16" Height="16" Margin="3,0" Source="Images\RegionXX.png" />-->
34.
<
TextBlock
Text
=
"{Binding Name}"
Foreground
=
"#FF1E4BAC"
/>
35.
</
StackPanel
>
36.
37.
</
DockPanel
>
38.
</
HierarchicalDataTemplate
>
39.
</
UserControl.Resources
>
40.
<
DockPanel
LastChildFill
=
"True"
>
41.
<
TextBlock
DockPanel.Dock
=
"Top"
Background
=
"CornflowerBlue"
x:Name
=
"Message"
/>
42.
<
telerik:RadTreeView
x:Name
=
"Tags"
DockPanel.Dock
=
"Bottom"
43.
ItemsSource
=
"{Binding Path=Tags}"
44.
ItemTemplate
=
"{StaticResource hierarchicalDataTemplate}"
45.
ItemContainerStyle
=
"{StaticResource radTreeViewItemStyle}"
46.
47.
>
48.
<!--<telerik:RadTreeViewItem Name="Item" Header="Root"></telerik:RadTreeViewItem>-->
49.
<!--Background="#FFE2E8F2"-->
50.
<!--ItemsSource="{Binding Path=Tags}"-->
51.
<!--<
telerik:RadTreeView.Items
>
52.
<
telerik:RadTreeViewItem
Name
=
"Item"
Header
=
"Root"
></
telerik:RadTreeViewItem
>
53.
</
telerik:RadTreeView.Items
>-->
54.
55.
</
telerik:RadTreeView
>
56.
</
DockPanel
>
57.
</
UserControl
>
tagsViewModel.cs
01.
using
Caliburn.Micro;
02.
using
System;
03.
using
System.Collections.Generic;
04.
using
System.Collections.ObjectModel;
05.
using
System.Linq;
06.
using
System.Text;
07.
using
System.Threading.Tasks;
08.
09.
namespace
Notizen.ViewModels
10.
{
11.
public
class
TagsViewModel : Screen
12.
{
13.
private
TagViewModel tag;
14.
15.
public
string
Message {
get
;
set
; }
16.
17.
public
TagsViewModel()
18.
{
19.
Tags =
new
ObservableCollection<TagViewModel>();
20.
}
21.
22.
public
TagViewModel RootTag
23.
{
24.
get
25.
{
26.
return
this
.tag;
27.
}
28.
29.
set
30.
{
31.
this
.tag = value;
32.
Tags.Add(value);
33.
NotifyOfPropertyChange(()=> Tags);
34.
}
35.
}
36.
37.
public
ObservableCollection<TagViewModel> Tags
38.
{
39.
get
;
40.
set
;
41.
}
42.
}
43.
}
shellviewModel.cs
01.
using
System;
02.
using
Notizen.ViewModels;
03.
using
Notizen.Model;
04.
using
System.Linq;
05.
using
Caliburn.Micro;
06.
using
System.Collections.ObjectModel;
07.
using
System.ComponentModel.Composition;
08.
09.
namespace
Notizen {
10.
[Export(
typeof
(IShell))]
11.
public
class
ShellViewModel : Caliburn.Micro.PropertyChangedBase, IShell {
12.
13.
private
TagViewModel _tags;
14.
public
TagViewModel TagViewModel
15.
{
16.
get
{
return
_tags; }
17.
set
{
18.
if
(_tags != value)
return
;
19.
_tags = value;
20.
NotifyOfPropertyChange(()=> TagViewModel);
21.
}
22.
}
23.
24.
private
string
_helloText;
25.
26.
public
string
HelloText
27.
{
28.
get
{
return
_helloText; }
29.
set
{ _helloText = value; }
30.
}
31.
32.
public
TagsViewModel Tags {
get
;
set
; }
33.
34.
35.
public
ShellViewModel()
36.
{
37.
LoadTags();
38.
HelloText =
"Hello!"
;
39.
40.
}
41.
42.
private
void
LoadTags()
43.
{
44.
using
(var context =
new
NotizenDbContext())
45.
{
46.
var roottag = context.Tags.Where(x => x.TagParentId ==
null
).FirstOrDefault();
47.
48.
//var tagViewModel = new TagViewModel(roottag, null);
49.
50.
//TagViewModel = tagViewModel;
51.
52.
Tags =
new
TagsViewModel() { Message =
"Message from TestViewModel"
, RootTag = tagViewModel };
53.
}
54.
}
55.
}
56.
}