Until version 3.5 WPF still lacks many useful controls natively such as Calendar, Date Picker and Data Grid. On the other hand, the WPF Toolkit for WPF 3.5 provides these complementally:
In this post, we are going to talk about how to host the Calendar control of the WPF Toolkit in a User Control and in turn a WPF Window.
Add the WPF Toolkit references first into the Revit WPF addin project:
Drag and drop the Calendar control from the WPF Toolkit catalog as in the first illustration onto the User Control of our concern:
We removed the elliptical button that we demonstrated before and added the Calendar control here into the UserControl4 as can be seen. Here is the full content of the UserControl XMAL code:
<UserControl x:Class="RevitAddinCSWPF.UserControl4"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Luna;component/themes/luna.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Rectangle Width="Auto" Height="Auto">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="Azure" Offset="0.0" />
<GradientStop Color="Orchid" Offset="0.15" />
<GradientStop Color="Purple" Offset="0.25" />
<GradientStop Color="RosyBrown" Offset="0.5" />
<GradientStop Color="Purple" Offset="0.75" />
<GradientStop Color="Orchid" Offset="0.85" />
<GradientStop Color="Azure" Offset="1.0" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<!--<Button Margin="53,49,34,0" Name="button1" Click="button1_Click" Height="35" VerticalAlignment="Top">Hello from WPF</Button>-->
<Button Height="27" HorizontalAlignment="Left" Name="button2" VerticalAlignment="Top" Width="24">TL</Button>
<Button Height="27" HorizontalAlignment="Left" Name="button3" VerticalAlignment="Bottom" Width="24">BL</Button>
<Button Height="27" HorizontalAlignment="Right" Name="button4" VerticalAlignment="Top" Width="24">TR</Button>
<Button Height="27" HorizontalAlignment="Right" Name="button5" VerticalAlignment="Bottom" Width="24">BR</Button>
<Button Height="27" HorizontalAlignment="Left" Margin="53,0,0,33" Name="button_Cancel" VerticalAlignment="Bottom" Width="84" Click="button_Cancel_Click">Cancel</Button>
<Button Height="27" HorizontalAlignment="Right" Margin="0,0,34,33" Name="button_OK" VerticalAlignment="Bottom" Width="84" Click="buttonOK_Click">OK</Button>
<CheckBox Height="16" Margin="30,5.52,150,0" Name="checkBox1" VerticalAlignment="Top">CheckBox</CheckBox>
<CheckBox Height="16" Margin="30,27,150,0" Name="checkBox2" VerticalAlignment="Top">CheckBox</CheckBox>
<RadioButton Height="16" Margin="130,5,50,0" Name="radioButton1" VerticalAlignment="Top">RadioButton</RadioButton>
<CheckBox Height="16" Margin="30,49,150,0" Name="checkBox3" VerticalAlignment="Top">CheckBox</CheckBox>
<RadioButton Height="16" Margin="130,27,50,0" Name="radioButton2" VerticalAlignment="Top">RadioButton</RadioButton>
<RadioButton Height="16" Margin="130,49,50,0" Name="radioButton3" VerticalAlignment="Top">RadioButton</RadioButton>
<my:Calendar Margin="53,71,50,76" Name="calendar1" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" />
</Grid>
</UserControl>
Now the project should build well and we are ready to give it a try immediately by pressing the F5 since Revit Addin Wizard (RevitAddinWizard) has already set up the debugging settings for us automatically.
If the ExtCmd4 ribbon button of the RevitAddinCSWPF ribbon panel is clicked, the WPF Window hosting the User Control and in turn hosting the WPF Toolkit Calendar control will show up as expected:
More articles about WPF and Revit Addin/API can be expected. Please stay tuned.
RevitAddinWizard may provide a few coders to address some WPF usage cases in the near future.
Recent Comments