I am developing a windows app which allows users to order Ice Creams.
I am trying to make a button to navigate to another page called "logorder" but keep getting an error. I have uploaded a picture to show the error.
Code
Public NotInheritable Class MainPage
Inherits Page
Public Property NavigationService As Object
''' <summary>
''' Invoked when this page is about to be displayed in a Frame.
''' </summary>
''' <param name="e">Event data that describes how this page was reached.
''' This parameter is typically used to configure the page.</param>
Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
' TODO: Prepare the page for display here.
' TODO: If your application contains multiple pages, ensure that you are
' handling the hardware Back button by registering for the
' Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
' If you are using the NavigationHelper provided by some templates,
' this event is handled for you.
End Sub
Private Sub HyperlinkButton_Click(sender As Object, e As RoutedEventArgs)
End Sub
Private Sub button_Copy_Click(sender As Object, e As RoutedEventArgs) Handles button_Copy.Click
NavigationService.Navigate(New Uri("/logorder.xaml", UriKind.Relative))
End Sub
End Class
Xaml...
<Page
x:Class="mobileapps.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:mobileapps"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Button x:Name="button_Copy" Content="Summary" HorizontalAlignment="Left" Margin="96,425,0,0" VerticalAlignment="Top" Width="191"/>
<HyperlinkButton Content="HyperlinkButton" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<HyperlinkButton Content="HyperlinkButton" HorizontalAlignment="Left" Margin="-232,186,0,0" VerticalAlignment="Top"/>
<HyperlinkButton Content="HyperlinkButton" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<HyperlinkButton Content="HyperlinkButton" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<HyperlinkButton Content="Log order" HorizontalAlignment="Left" Margin="134,332,0,0" VerticalAlignment="Top" RenderTransformOrigin="-0.106,-0.496" Click="HyperlinkButton_Click" NavigateUri="logorder.xaml"/>
<HyperlinkButton NavigateUri="logorder.xaml" />
</Grid>
You never set NavigationService, but try to call a method on it, so you will get a NullReferenceException
Try this
Private Sub HyperlinkButton_Click(sender As Object, e As RoutedEventArgs)
Me.Frame.Navigate(GetType(BasicPage2))
End Sub
How to perform navigation between pages in windows phone
Similar SO Question
Related
I have recently upgraded my OS to Windows 10 from Windows 8.1. I'm using VS 2013 With update 4.
My app using the Treeview control from XAMLToolkit, and it works perfectly on Windows 8.1 environment. But under Windows 10, it gives me the following error.
Please help.
This is the XAMLToolkit version I've used:
nuget.org/packages/winrtxamltoolkit.windows
Exception message:
System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
at Windows.UI.Xaml.Controls.ItemsControl.get_ItemTemplate()
at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainer(HeaderedItemsControl control, Object item, ItemsControl parentItemsControl, Style parentItemContainerStyle)
at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainerForItemOverride(DependencyObject element, O
Stacktrace:
at Windows.UI.Xaml.Controls.ItemsControl.get_ItemTemplate()
at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainer(HeaderedItemsControl control, Object item, ItemsControl parentItemsControl, Style parentItemContainerStyle)
at WinRTXamlToolkit.Controls.HeaderedItemsControl.PrepareHeaderedItemsControlContainerForItemOverride(DependencyObject element, Object item, ItemsControl parent, Style parentItemContainerStyle)
at WinRTXamlToolkit.Controls.TreeView.PrepareContainerForItemOverride(DependencyObject element, Object item)
at Windows.UI.Xaml.FrameworkElement.MeasureOverride(Size availableSize)
Inner exception is null
I encountered same issue, what i did is just removed the itemtemplate inside treeview control and added separately in page resource and i refered the itemtemplate to my treeview control. it solved my issue.
<Page.Resources>
<DataTemplate x:Name="TreeViewItemTemplate">
<Grid>
<TextBlock Text="{Binding Name}" />
</Grid>
<XCDATA:DataTemplateExtensions.Hierarchy>
<XCDATA:HierarchicalDataTemplate ItemsSource="{Binding Items}" />
</XCDATA:DataTemplateExtensions.Hierarchy>
</DataTemplate>
</Page.Resources>
<XC:TreeView
ItemTemplate="{StaticResource TreeViewItemTemplate}"
ItemsSource="{Binding ObjShopItems}">
</XC:TreeView>
Seems that you are using a HierarchicalDataTemplate in your XAML code for the TreeView. Replacing the XAML with the corresponding C# code will help. We can set the DataTemplateExtensions.Hierarchy attached property in code-behind in Loaded event for the TreeView, like this:
<controls:TreeView x:Name="treeView"
Loaded="treeView_Loaded"
...
And in code-behind:
private void treeView_Loaded(object sender, RoutedEventArgs e)
{
//don't know why, but in Windows 10 if this code is as XAML, the app falls with a ComExcpetion
//so the corresponding XAML should be commented out like this:
//...
//<controls:TreeView.ItemTemplate>
// <DataTemplate>
// <!-- <data:DataTemplateExtensions.Hierarchy>
// <data:HierarchicalDataTemplate ItemsSource="{Binding Folders}" />
// </data:DataTemplateExtensions.Hierarchy> -->
// <Grid>
//...
WinRTXamlToolkit.Controls.Data.DataTemplateExtensions.SetHierarchy(treeView.ItemTemplate, new WinRTXamlToolkit.Controls.Data.HierarchicalDataTemplate
{
ItemsSource = new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath("Folders") }
});
}
In my WinRT/Phone 8.1 app I have a form with a number of Grids (serving as wrappers) each containing two or more TextBlocks. I want to show only data that is available, meaning that if the content TextBlock of a particular Grid is empty I want to hide the entire Grid.
For instance:ยด
<Grid x:Name="NameSection">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
x:Name="NameLabel"
Text="Name:" />
<TextBlock Grid.Row="1"
x:Name="Name"
Text="{Binding Name}" />
</Grid>
If the Name TextBlock is empty, the entire Grid's visibility should be collapsed.
Adding logic for this either to code behind or (worse) the ViewModel could get messy for this long form, so I wonder if I can achieve this using XAML and styles. How can it be done in WinRT? Can I style the Grid such that it's visibility is based on the content in one of its subviews?
Converter
public class NullToVisibilityConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return value == null ? Visibility.Collapsed: Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
then use it like this
<Grid x:Name="NameSection" Visibility={Binding Name, Converter={StaticResource MyNullConverter}}>
edit:
you can add string.IsNullOrEmpty(value as string) insted of value == null, if you want to check empty strings as well
I'm working on a Windows 8.1 app. I have added a basic page to my project, which automatically adds a back button:
<Button x:Name="backButton"
Margin="39,59,39,20"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top" />
The button works fine. However, when I move this button to an AppBar, it doesn't work. The view doesn't go back to the previous page.
What is going wrong in the latter case?
The AppBar isn't in the same namespace as the page and so the Command binding to the page's NavigationHelper property doesn't resolve. This is the case for any binding of the AppBar to the page.
You can fix this by setting the AppBar's DataContext to the page in page.Loaded
XAML
<Page.BottomAppBar>
<AppBar x:Name="bottomAppBar" IsOpen="True">
<Button x:Name="backButton"
Margin="39,59,39,20"
Command="{Binding NavigationHelper.GoBackCommand}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top" />
</AppBar>
</Page.BottomAppBar>
C#
public BasicPage1()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
this.Loaded += BasicPage1_Loaded;
}
async void BasicPage1_Loaded(object sender, RoutedEventArgs e)
{
bottomAppBar.DataContext = this;
}
--Rob
I am developing windows phone app..
I am taking 1 button and on click of that button the dropdown list of clothes should come..
how to code for this?
Problem: How to take this list on button click
Your xaml should be :
<Button x:Name="BtnShowCloth" Content="showCloth" Margin="10,5" Click="BtnAddProduct_Click"/>
<toolkit:ListPicker ExpansionMode="FullScreenOnly" x:Name="ClothListPicker" Visibilty="Collapsed" Margin="0,0,0,10" Height="100" >
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}"/>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}" Margin="2,10,0,0" FontSize="31"/>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
//Another way use ListBox Control
<ListBox Grid.Row="1" Name="ListBoxCloth" Height="50">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource AppTextBlockStyle}" Text="{Binding}" Margin="2,10,0,0" FontSize="31"/>
</DataTemplate>
<ListBox.ItemTemplate>
</ListBox>
Code Behind of button click fill list of cloth names. In windows phone no dropdown list exist, you should use longlistselector instead of dropdown
private void BtnAddProduct_Click(object sender, RoutedEventArgs e)
{
List<string> clothNameList = new List<string>();
clothNameList .Add("a");
clothNameList .Add("b");
clothNameList .Add("c");
clothNameList .Add("d");
clothNameList .Add("e");
//ClothListPicker.ItemsSource = clothNameList;
// ClothListPicker.Visibility = Visibility.visible;
ListBoxCloth.ItemsSource = clothNameList;
ListBoxCloth.Height = 400;
}
This is very broad question, infact does not fall in SO standards of Questions.
You should research and try something and ask only if you got stuck somewhere or if your method fails.
And to your question, it needs clarification on many things like
What is the format of your clothes data
Are you getting it from a web service or a local db or some other resource
Is it a single List or a groups of items etc
Hence, it becomes hard to answer. Please keep these things in mind, next time when asking questions.
Based on your comment:
You should split your task into multiple small tasks
First thing, learn how to fetch the data from your db
Converting that data into List of objects
Creating your UI for the data
Bind the data to the UI in your Button_Click event handler
Happy coding !!
Using a SemanticZoom control in an MVVM project, I have two ListView controls with custom styles and panels, etc. so they display horizontally, there is no grouping or need for it.
I bind both to a CollectionViewSource in the view model.
When I click an item in the zoomed-out view, it doesn't take focus to that item in the zoomed-in view.
How can I achieve this?
Edit
Added XAML code:
<SemanticZoom>
<SemanticZoom.ZoomedInView>
<ListView
Style="{StaticResource HorizontalListViewStyle}"
SelectionMode="None"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ItemsSource="{Binding BoardItems}"
ItemContainerStyle="{StaticResource ZoomedOutListViewItemContainerStyle}">
</ListView>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<ListView x:Name="listView"
Style="{StaticResource HorizontalListViewStyle}"
SelectionMode="None"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ItemsSource="{Binding BoardItems}"
ItemContainerStyle="{StaticResource ZoomedOutListViewItemContainerStyle}">
</ListView>
</SemanticZoom.ZoomedOutView>
</SemanticZoom>
Both of your ZoomedInView and ZoomedOutView need to have ScrollViewer.IsHorizontalScrollChainingEnabled="False" in order to scroll properly.
In codebehind for the page (or using an attached property), handle the ViewChangeStarted event with this code:
private void zoomyThingWoo_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
{
if (e.SourceItem.Item != null)
{
e.DestinationItem.Item = e.SourceItem.Item;
}
}
That's it. The documentation makes it sound like SemanticZoom will just work with any two controls that implement ISemanticZoomInfo but it doesn't.
I raised a documentation bug with the XAML team in Redmond.