I am working on a project right now that has to separate project files. One complies in Silverlight 3 and the other in Silverlight 4. The project creates a user control that is used in a couple other projects. Unfortunately one is in SL3 and cant be upgraded right now which is why a SL3 version of the control is needed.
So far it has worked out fine but recently I tried to add a ViewBox to the control. This causes a problem because in SL3 it is located in the toolbox and in SL4 it is in the core.
Is there any way to have it pull from the toolkit in the SL3 project and the core in the SL4 project? I looked into preprocessor definitions in xaml and found some info but I don't like how it kills the ability to load the code in the designer.
What I ended up doing is creating a border around the inner viewbox elements. Then I got rid of the viewbox in xaml. When I load the control I set the child of the containing border to null, create a viewbox in code, and set its child to the inner border. Then I set the child of the containing border to the viewbox.
<Border Name="viewBoxContainer">
<Border x:Name="innerBorder">
<TextBlock x:Name="innerText" Text="Test" />
</Border>
</Border>
Code Behind
this.viewBoxContainer.Child = null;
this.viewBoxContainer.Child = new Viewbox { Child = this.innerBorder};
No, there is no support for conditional complication within XAML. How about creating your own subclass within each project:
within the SL3 project:
using //namespace for SL3 ViewBox
namepsace MyProjectNamespace
{
public class MyViewBox : ViewBox
{
}
}
within the SL4 project:
using //namespace for SL4 ViewBox
namepsace MyProjectNamespace
{
public class MyViewBox : ViewBox
{
}
}
within your common XAML file:
<UserControl ...
xmlns:local="clr-namespace:MyProjectNamespace">
<local:MyViewBox>
.. content goes here ..
</local:MyViewBox>
</UserControl>
We had the same problem, and our solution was to make our own viewbox that was used across the board.
Bascially, we just took the source code for Viewbox provided in the SL3 toolkit, copied it and put it in our own namespace, then renamed it to something like MyViewbox.
I'm not sure this is the best solution, but it worked out well for us.
Related
Since a change in MahApps.Metro 1.5.0 the base element of a Flyout was changed from ContentControl to HeaderContentControl. Now the MVVM approach with Caliburn.Micro and this suggestion doesn't work anymore.
Has anybody else tried to solve this issue in a nice MVVM way?
While I haven't tried it myself but since the new Flyout control is now based on HeaderedContentControl it would be a simple logic choice to attempt to do this instead of the previous, which was based on ContentControl. Looks like the advantages of this change were the elimination of a couple of dependency properties...
<controls:FlyoutsControl.ItemTemplate>
<DataTemplate>
<HeaderedContentControl cal:View.Model="{Binding}" />
</DataTemplate>
</controls:FlyoutsControl.ItemTemplate>
The other thing that might come out of this that you create a Caliburn.micro convention to actually bind correctly to that HeaderedContentControl which wouldn't be all that different from the ContentControl variant was, by default in CM already. What is odd is that this HeaderedContentControl is derived from ContentControl in theory it should have been found correctly. Another thing to think about is this actually might also be related to Visual Tree where CM can't see it till it's in the tree, therefore can't bind it.
Content Control convention in CM source as a reference.
I've added posted a work around on GitHub.
It appears there's something going on with setting the ItemTemplate of the FlyoutsControl.
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" />
Currently we have a WPF userControl Library where the namespaces are mapped to an XML Namespace using the
[assembly: XmlnsDefinition]
statement.
When we try to use controls out of this library in a WPF Application that references this assembly, using a ContentPresenter
<ContentPresenter Content="{Binding CurrentContent, Converter={StaticResource ViewModelToViewConverter}}" />
we always get a
System.Windows.Markup.XamlParseException("Type reference cannot find type named '{http://schemas.microsoft.com/winfx/2006/xaml/presentation}XYZView")
What are we doing wrong - or is catel not designed to show controls using the ViewModelToViewConverter if they are in a XmlnsDefinition?
Okay, fixed - the error was on another place in the source... Catel definitely works also when using Xmlnsdefinitions.
I was reading this article - http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
And I came across this piece of code in the WPF Demo application that came with the article.
This template applies a CustomerView to an instance of the CustomerViewModel class shown in the main window.
<DataTemplate DataType="{x:Type vm:CustomerViewModel}">
<vw:CustomerView />
</DataTemplate>
I substituted the angle brackets for square brackets - not sure how to post them.
The code is in the MainWindowResourses.xaml and the code starts on line 19.
Anyone know how I can do this in Silverlight ??
We don't have the DataType and I need to be able to tell the app that this View is associated with this ViewModel - so I can create a tab control with different view like the demo app.
Cheers,
EC
This is an example of WPF implicit styling, where a style is applied to all the controls in the project. This is not supported in Silverlight.
To get around this you need to instead place your view controls in the markup and set their DataContext to the viewmodel.
<Window.Resources>
<vm:CustomerViewModel x:Key="theViewModel">
<Window.Resources>
<vw:CustomerView DataContext={StaticResource theViewModel}/>
theViewModel doesn't have to come from the resources section, it could be a property in the hosting XAML control/page.
I am having a strange issue opening up my UserControl in Expression Blend when using a Silverlight Toolkit control. My UserControl uses the toolkit's ListBoxDragDropTarget as follows:
<controlsToolkit:ListBoxDragDropTarget mswindows:DragDrop.AllowDrop="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
<ListBox ItemsSource="{Binding MyItemControls}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<controlsToolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</controlsToolkit:ListBoxDragDropTarget>
Everything works as expected at runtime and looks fine in Visual Studio 2008. However, when I try to open my UserControl in Blend I get XamlParseException: [Line: 0 Position: 0] and I can not see anything in the design view. More specifically Blend complains:
The element "ListBoxDragDropTarget" could not be displayed because of a problem with System.Windows.Controls.ListBoxDragDropTarget: TargetType mismatch.
My silverlight application is referencing System.Windows.Controls.Toolkit from the Nov. 2009 toolkit release, and I've made sure to include these namespace declarations for the ListBoxDragDropTarget:
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:mswindows="clr-namespace:Microsoft.Windows;assembly=System.Windows.Controls.Toolkit"
If I comment out the ListBoxDragDropTarget control wrapper and just leave the ListBox I can see everything fine in the design view without errors. Furthermore, I realized this is happening with a variety of Silverlight Toolkit controls because if I comment out ListBoxDragDropTarget and replace it with
<controlsToolkit:BusyIndicator />
the same exact error occurs in Blend. What is even weirder is that if I start a brand new silverlight application in blend I can add these toolkit elements without any kind of error, so it seems like something dumb that is happening with my project references to the toolkit assemblies.
I'm pretty sure this has something to do with loading the default styles for the toolkit controls from its generic.xaml, since the error has to do with the TargetType and Blend is probably trying to load up the default styles.
Has anyone encountered this issue before or have any ideas as to what may be my problem?
Hi we had exactly the same issue, we solved it by checking the references in the project which was having this problem. All referenced toolkit assemblies should be in the same directory on disk.
Our project reference to the System.Windows.Controls.Toolkit.dll always 'jumped' back to the orginal path which was causing our issue. We solved by editing the project file in notepad++ (or any of your favorite text-editor) and hardcode the path where it could find the assembly.
Hope this helps.
For Visual Studio (maybe Blend too) you need to add a reference to :
System.Windows.Controls.Toolkit.Internals.dll
"C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Bin\System.Windows.Controls.Toolkit.Internals.dll"
I'm using Silverlight 5 toolkit and having XamlParseException when using BusyIndicator toolkit control in Expression Blend for SL 5, all above solutions didn't helped but I found another workaround, its rather dirty but allows me to make BusyIndecator work in Expression Blend,
derive from control
public class BusyIndicatorEx : BusyIndicator
{
public BusyIndicatorEx()
{
this.DefaultStyleKey = typeof(BusyIndicatorEx);
}
}
create style for derived control (just copy style from BusyIndicator source code to themes/generic.xaml, and change target type to local:BusyIndicatorEx)
I had the same problem which has been resolved by introducing a dummy reference in code behind to the Wrap Panel.
I know it is a little C++y but I can imagine it is because we have indirect reference to wrap panel inside a template and not on the top level page so the loader don't know what to load on initialization. I really like understand the exact reason, though.
I just referenced System.Windows.Controls.Toolkit and introduce following member in code behind:
System.Windows.Controls.WrapPanel _dummy;