Prism release mode causing an error - prism

Redoing this question (sorry to anyone who was in the middle of reading it)
Attempting to play with Prism 6, but I'm getting an issue on all of my shellview components, when I'm working in debug mode everything is fine, however the moment I switch to release mode I'm getting a lot of errors.
Error CS0246 The type or namespace name 'BindableBase' could not be found
(are you missing a using directive or an assembly reference?)
ShellModule C:\Dev\Prism_Prototype\Source\ShellModule\ViewModels\TitleControlViewModel.cs
This is happening in pretty much every file. On hovering over the error I get the option to add a reference to Prism, and add using for Prism.MVVM, but there's already a reference there, and after adding the reference back in all I get is a new error stating
The type or namespace name "BindableBase" could not be found, are you missing
a using directive or assembly reference.
Here's one of the files which is going wrong as an example.
using Prism.Mvvm;
using ShellModule.ViewModels.Interfaces;
namespace ShellModule.ViewModels
{
public class TitleControlViewModel : BindableBase, ITitleControlViewModel
{
private string _content = "This is my content";
public string Content
{
get { return _content; }
set { SetProperty(ref _content, value); }
}
}
}
And TitleControlView.xaml
<UserControl
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:mvvm="http://prismlibrary.com/"
mc:Ignorable="d"
mvvm:ViewModelLocator.AutoWireViewModel="true"
x:Class="ShellModule.Views.TitleControlView"
HorizontalContentAlignment="Stretch">
<UserControl.Resources>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="100*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label x:Name="DekLogo" Background="{DynamicResource SolidColourASMDefaultRed}" Width="180" Height="60" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Column="0" Padding="1" >
<Image Source="{DynamicResource DekLogo}" Height="36" Width="110" />
</Label>
<Label x:Name="Notifications" Background="{DynamicResource SolidColourDefaultBackground}" HorizontalContentAlignment="Stretch" Grid.Column="1" Content="{Binding Content}" />
<Label x:Name="SiplaceLogo" Background="{DynamicResource SolidColourBackground}" Width="180" Height="60" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Grid.Column="2" Padding="1">
<Image Source="{DynamicResource Logo}" Height="36" Width="110" />
</Label>
</Grid>
</UserControl>

Solved my own problem after playing around a bit more.
For some reason (probably during refactoring) my references were messed up in release mode. Went through and uninstalled all the nuget packages I had been using for Prism and Ninject, then reinstalled all the packages, low and behold the problem has been fixed.
Still no idea why it happened in the first place though.

Related

Converting CarouselPage to CarouselView

Is it possible to add direct content to a CarouselView in Xaml?
I need to convert an old CarouselPage to the newer CarouselView, but it looks like it must be data bound. But my content for each slide is entirely different and does not easily lend itself to an item template.
<?xml version="1.0" encoding="utf-8" ?>
<CarouselPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="myCarousel"
x:Name="carouselPage"
NavigationPage.HasNavigationBar="false" BackgroundColor="#000000">
<ContentPage BackgroundColor="#000000">
<StackLayout BackgroundColor="#000000">
<Label Text="Lorem ipsum" />
<ImageButton Margin="0,20" Source="btn_continue" HorizontalOptions="Center" HeightRequest="30" Clicked="Go_Right" />
</StackLayout>
</ContentPage>
<ContentPage BackgroundColor="#000000">
<StackLayout BackgroundColor="#000000">
<Button Text="X" TextColor="White" BackgroundColor="Transparent" VerticalOptions="Start" HorizontalOptions="End" Clicked="Go_Home"></Button>
<ImageButton Source="slider-2" Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="Start" />
<Grid Margin="0,20" VerticalOptions="Start">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ImageButton Source="btn_back" HorizontalOptions="Center" HeightRequest="30" Grid.Column="0" Clicked="Go_Left" />
<ImageButton Source="btn_close" HorizontalOptions="Center" HeightRequest="30" Grid.Column="1" Clicked="Go_Home" />
</Grid>
</StackLayout>
</ContentPage>
</CarouselPage>
I need to create a multi-slide carousel, where each slide has different content like above. How would I convert that using CarouselViews?
The problem I am having with the CarouselPage is that it does not always behave consistently, which is why I imagine they are slowly deprecating it.
But my content for each slide is entirely different and does not
easily lend itself to an item template.
You need to create different DataTemplate for each slide and Choose item appearance at runtime, for example:
<ContentPage ...
xmlns:controls="clr-namespace:CarouselViewDemos.Controls"
x:Class="CarouselViewDemos.Views.HorizontalLayoutDataTemplateSelectorPage">
<ContentPage.Resources>
<DataTemplate x:Key="StyleATemplate">
...
</DataTemplate>
<DataTemplate x:Key="StyleBTemplate">
...
</DataTemplate>
<controls:ContentSelector x:Key="myContentSelector"
AmericanMonkey="{StaticResource StyleATemplate}"
OtherMonkey="{StaticResource StyleBTemplate}" />
</ContentPage.Resources>
<CarouselView ItemsSource="{Binding Monkeys}"
ItemTemplate="{StaticResource myContentSelector}" />
</ContentPage>
And in code behind, use DataTemplateSelector to select different template for each slide:
public class ContentSelector: DataTemplateSelector
{
public DataTemplate StyleATemplate{ get; set; }
public DataTemplate StyleBTemplate{ get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
if(item.style == A){
return StyleATemplate;
}else{
return StyleBTemplate;
}
}
}
Yes of course you can add different content on every view.
It's necessary to create a CustomViewSelector.
Check my GitHub for a full sample code https://github.com/georgemichailou/ShaXam
Pay attention to these files
https://github.com/georgemichailou/ShaXam/blob/master/ShaXam/UI%20Helper/CustomViewSelector.cs
https://github.com/georgemichailou/ShaXam/blob/master/ShaXam/MainPage.xaml
https://github.com/georgemichailou/ShaXam/blob/master/ShaXam/MainPage.xaml.cs (Line 17-25-27)

Control template Binding Not working in MVVM Cross Xamarin Forms

I am currently working on a Xamarin Forms project which is using MVVMCross. In App.xaml i created a control template as follows
<ControlTemplate x:Key="ContentPageTemplate">
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" RowSpacing="0" RowDefinitions="Auto,Auto,*">
<!--StackLayout as Header-->
<StackLayout Grid.Row="0" HeightRequest="6" BackgroundColor="{StaticResource SecondaryBrandColor}"></StackLayout>
<Frame Padding="0" Grid.Row="1" >
<Label Grid.Row="1" Text="Server Not Available" BindingContext="{TemplateBinding BindingContext}"
Style="{StaticResource ServerAvailableLabel}"
IsVisible="{TemplateBinding Parent.BindingContext.IsServerAvailableLabelVisible}"/>
</Frame>
<!--Content Page Body-->
<ContentPresenter Grid.Row="2" BackgroundColor="{StaticResource PrimaryBodyColor}">
</ContentPresenter>
</Grid>
</ControlTemplate>
Now i am using this control template in contentPage as follows
<views:MvxContentPage xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Project.UI.Views.ReqView"
ControlTemplate="{StaticResource ContentPageTemplate}"
Title="Reqs">
</views:MvxContentPage>
In the view model i am trying to make the label visible and invisible as follows
public bool _isServerAvailableLabelVisible = false;
public bool IsServerAvailableLabelVisible
{
get
{
return _isServerAvailableLabelVisible;
}
set
{
SetProperty(ref _isServerAvailableLabelVisible, value);
}
}
The problem i am facing now is, by default the label is being visible and also it is not updating even when i am setting the value as false.
What am i missing ?
I had exactly the same issue !
After one day I found the following solution which works for me.
I added BindingContext="{TemplateBinding BindingContext.DataContext}"into the Grid and change the IsVisible property by IsVisible="{Binding IsServerAvailableLabelVisible}"
Here the recap that you can try, hope it will work for you too !
For information I use Xamarin.Forms 4.8.0 & MvvmCross 6.3.1
<ControlTemplate x:Key="ContentPageTemplate">
<Grid HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" RowSpacing="0" RowDefinitions="Auto,Auto,*"
BindingContext="{TemplateBinding BindingContext.DataContext}">
<!--StackLayout as Header-->
<StackLayout Grid.Row="0" HeightRequest="6" BackgroundColor="{StaticResource SecondaryBrandColor}"></StackLayout>
<Frame Padding="0" Grid.Row="1" >
<Label Grid.Row="1" Text="Server Not Available"
Style="{StaticResource ServerAvailableLabel}"
IsVisible="{Binding IsServerAvailableLabelVisible}"/>
</Frame>
<!--Content Page Body-->
<ContentPresenter Grid.Row="2" BackgroundColor="{StaticResource PrimaryBodyColor}">
</ContentPresenter>
</Grid>
</ControlTemplate>
Are you sure that the OnPropertyChanged Event gets fired when you chcange the value?
If yes then you need to check the binding context of the view
If no you need to fire it manually (as mentioned in the MVVMCross documentation)
private string _myProperty;
public string MyProperty
{
get => _myProperty;
set
{
_myProperty = value;
RaisePropertyChanged(() => MyProperty);
// take any additional actions here which are required when MyProperty is updated
}
}

Silverlight Value does not fall within expected range when trying to open a xaml

I receive the following message in a simple message pop up, when trying to open the designer of some of my xaml files:
"Value does not fall within expected range"
I've tried to create a new windows and open the xaml files in notepad and copy them in the new one, but even with a new control it gives me this error without even having modifying it.
Here's one of the xamls that gives me an error:
<controls:ChildWindow x:Class="Playground.Views.MessageWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="343" Height="159"
Title="MessageWindow" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="316*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="216*" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,9,0,0" Grid.Row="1" Grid.ColumnSpan="2" />
<dxe:TextEdit HorizontalAlignment="Stretch" VerticalAlignment="Stretch" VerticalContentAlignment="Top" HorizontalContentAlignment="Left" Name="txtMessage" IsReadOnly="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap" Background="#FFE7E9EC" />
</Grid>
And here's one that doesn't have this problem:
<controls:ChildWindow x:Class="Playground.Views.LogIn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="270" Height="200"
Title="Log In" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
<Button x:Name="OKButton" Content="Log In" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="18,23,0,0" Name="label1" VerticalAlignment="Top" Width="60" Content="Username" />
<sdk:Label Height="23" HorizontalAlignment="Left" Margin="18,56,0,0" Name="label2" VerticalAlignment="Top" Width="60" Content="Password" />
<dxe:CheckEdit HorizontalAlignment="Left" Margin="18,85,0,0" Name="checkEdit1" VerticalAlignment="Top" Width="92" Content="Use CIL/CIP" IsThreeState="False" Checked="checkEdit1_Checked" Unchecked="checkEdit1_Unchecked"/>
<dxe:CheckEdit Margin="116,85,0,0" Name="remUNCE" VerticalAlignment="Top" Content="Save Username" IsThreeState="False" HorizontalAlignment="Left" Width="120" Checked="remUNCE_Checked" Unchecked="remUNCE_Unchecked"/>
<dxe:TextEdit HorizontalAlignment="Left" Margin="86,23,0,0" Name="textEdit1" VerticalAlignment="Top" Width="136" Text="administrator" />
<dxe:PasswordBoxEdit HorizontalAlignment="Left" Margin="86,56,0,0" Name="passwordBoxEdit1" VerticalAlignment="Top" Width="136" />
</Grid>
I tried searching for this problem on the internet but all i got were results for duplicate names in the same xaml, which is not the case here, also i'm not injecting any controls in codebehind so there shouldn't be any problem regarding duplicate names.
i use visual studio 2010 and also in case it has any relevance i have devexpress installed, but when i started getting this error i had an earlier version so i upgraded it to the latest in hopes of fixing it, but no luck.

Xaml designer behaves differently in VS 2012 and VS 2010

I recently switched to Visual Studio 2012 from VS2010.
I have some user controls which are templates for other user controls.
The first ones have some ContentControl whose content is defined in the second ones.
Follows the definition of a user control based on a template control (ImpegniBaseView)
<localView:ImpegniBaseView>
<localView:ImpegniBaseView.ActionButtons>
<StackPanel Height="54" HorizontalAlignment="Left" VerticalAlignment="Top" Width="668" Orientation="Horizontal">
<Button Content="Salva" Height="31" Width="88" Command="{Binding Path=SaveCommand}" IsEnabled="{Binding Editable}" Margin="5,0" />
<Button Command="{Binding Path=CreateCommand}" Content="Nuovo impegno master" Height="31" Width="Auto"
Visibility="{Binding IsFirstLevelView, Converter={StaticResource BoolToVisibility}}"
IsEnabled="{Binding Path=Editable, Converter={StaticResource InverseBooleanConverter}}" Margin="5,0" />
</StackPanel>
</localView:ImpegniBaseView.ActionButtons>
</localView:ImpegniBaseView>
In Vs 2010 I could easily select, for example, the button 'Salva' in the designer. Now I cannot. I suppose I have to change an option in the designer, but I don't know which one...
Update
Follows the relevant part of the user control used as template
<UserControl x:Class="Ragioneria.View.ImpegniBaseView"
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:local="clr-namespace:Ragioneria"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="700">
<DockPanel DataContext="{Binding ImpegnoSelezionato}">
<DockPanel DockPanel.Dock="Top">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left">
<Label Content="Anno/Num-Sub" Height="28" HorizontalAlignment="Left" Margin="5" Name="label1" VerticalAlignment="Top" Width="Auto" />
<ContentControl Content="{Binding Path=IdentificazioneImpegnoSection, RelativeSource={RelativeSource AncestorType=UserControl}}" Width="400" Height="28" Margin="5" />
</StackPanel>
<TextBox Height="28" Width="100" Name="textBox9" Text="{Binding Path=DataRegistrazione, StringFormat=d}" DockPanel.Dock="Right" Style="{DynamicResource tb_readonly}" TextAlignment="Right" Margin="5" />
<Label Content="Data" Height="28" Margin="5" Name="label7" Width="50" DockPanel.Dock="Right"/>
</DockPanel>
<ContentControl DockPanel.Dock="Bottom"
DataContext="{Binding DataContext.ActiveWorkspace, RelativeSource={RelativeSource AncestorType=Window}}"
Content="{Binding Path=ActionButtons, RelativeSource={RelativeSource AncestorType=UserControl}}" />
</DockPanel>
Thanks
Filippo
You must add [AlternateContentProperty] to ActionButtons.
Unfortunately, unlike in Silverlight, you won't find this attribute in standard library.
Instead, you will need to use Microsoft.Windows.Design.PropertyEditing.AlternateContentProperty from Microsoft.Windows.Design.Interaction.dll.
Since this is a non-redistributable dll from Visual Studio, you can't reference it directly and have to create designer metadata assembly.
See this bug
and vote here.

Generating sample XML data for Blend from Entity Framework data model?

In working with MS Expression Blend, you can import sample data from an XML file to use to test your XAML and bindings in design mode. My data model is fully defined in XML using the Entity Framework. Is there any reasonable way to use that model, either directly or indirectly, as the source for the Blend sample data? It seems like this is a fairly obvious use case, but I haven't found any samples of how to do this. Is my only option to write a utility that serializes an instance of my EF classes to XML?
(I don't think I can use a link to the live datasource, because I'm using Silverlight w/ WCF, and my data model is the auto-generated proxy classes. If there's a way to hook Blend up to a WCF service, I have yet to find it -- though I'd be happy to get some pointers.)
I still don't have a great answer for this. I tried serializing some instances of my EF classes to XML using the DataContractSerializer:
DataContractSerializer serializer = new DataContractSerializer(typeof(Room));
using (SlideLincEntities ctx = new SlideLincEntities())
{
Room roomWithMostSessions = ctx.Room
.OrderByDescending(r => r.Sessions.Count)
.FirstOrDefault();
string fileName = ConfigurationSettings.AppSettings["outputFile"];
Console.WriteLine("Writing data to file '{0}'", fileName);
File.Delete(fileName);
using (Stream fileStream = File.Open(fileName, FileMode.OpenOrCreate))
{
serializer.WriteObject(fileStream, roomWithMostSessions);
}
}
Unfortunately, Blend can't read the generated XML: the DataContractSerializer uses XML ref notation, which apparently confuses Blend's simplistic XML deserializer.
I also tried generating sample data by hand (uggh) using XAML's object notation:
<rs:Room d:IsDataSource="True"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:rs="clr-namespace:SlideLinc.Client.Common.RoomService;assembly=SlideLinc.Client.Common"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
Name="_default" OwnerId="smithkl42"
>
<rs:Room.Owner>
<rs:RegisteredUser x:Name="ken" UserId="ken" Email="ken#hotmail.com" FirstName="Ken" LastName="Smith" MaxFileUploadSize="20000" UserName="Ken Smith" />
</rs:Room.Owner>
</rs:Room>
This was better, but for some reason, Blend wouldn't bind to any collections within the objects: I don't know why, because of course XAML databinding errors get swallowed silently. (Have I mentioned how much I hate XAML databinding?)
I eventually went with defining small amounts of data straight within the XAML form proper:
<ListBox x:Name="fileListBox" Grid.Row="2" Margin="4" BorderThickness="0" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25" />
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="5" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Image Source="/Images/Word.png" Grid.Column="0" Margin="2" />
<TextBlock Text="{Binding OriginalFileName}" Grid.Column="1" VerticalAlignment="Center" />
<HyperlinkButton Content="Share" Grid.Column="2" Margin="4" HorizontalAlignment="Right" VerticalAlignment="Center"/>
<HyperlinkButton Grid.Column="4" Margin="4" HorizontalAlignment="Right" VerticalAlignment="Center" >
<Image Source="/Images/trashcan.png" Width="25" />
</HyperlinkButton>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<!-- I shouldn't have to do this, but for some reason, I can't get sample data any other way -->
<roomservice:SharedFile OriginalFileName="Some Document.docx" />
<roomservice:SharedFile OriginalFileName="Another document.pptx"/>
</ListBox>
So that's my current approach. Not very elegant. Open to other ideas.

Resources