Skip to content

Instantly share code, notes, and snippets.

@magegu

magegu/page.cs Secret

Last active December 18, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magegu/0e0bd53fcef25ce6aa81 to your computer and use it in GitHub Desktop.
Save magegu/0e0bd53fcef25ce6aa81 to your computer and use it in GitHub Desktop.
public partial class FullscreenPage : PhoneApplicationPage
{
Item item;
public FullscreenPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string objectId;
NavigationContext.QueryString.TryGetValue("ObjectId", out objectId);
var itemsDB = new ItemsContext(ItemsContext.DBConnectionString);
item = (from r in itemsDB.artifacts where r.Id.Equals(objectId) select r).First();
}
}
<ContentControl ContentTemplate="{Binding}">
<testapp:FullscreenTypeSelector>
<testapp:FullscreenTypeSelector.ImageTemplate>
<ControlTemplate>
<StackPanel>
<Image Name="Image" Source="{Binding PayloadUri}"/>
</StackPanel>
</ControlTemplate>
</testapp:FullscreenTypeSelector.ImageTemplate>
<testapp:FullscreenTypeSelector.TextTemplate>
<ControlTemplate>
<StackPanel>
<TextBlock Name="MimeText" Text="{Binding Mime}"/>
</StackPanel>
</ControlTemplate>
</testapp:FullscreenTypeSelector.ImageTemplate>
</testapp:FullscreenTypeSelector>
</ContentControl>
public class FullscreenTypeSelector : ContentControl
{
public ControlTemplate ImageTemplate
{
get;
set;
}
public ControlTemplate TextTemplate
{
get;
set;
}
//Use ContentControl as a container and bind ContentTemplate property to your DataTemplateSelector.
ControlTemplate SelectTemplate(object item, DependencyObject container)
{
Item foodItem = item as Item;
if (foodItem != null)
{
if (foodItem.Mime == "note")
{
return TextTemplate;
}
else
{
return ImageTemplate;
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment