WinRTXAMLToolkit Treeview Crash on Windows 10 - windows-runtime

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") }
});
}

Related

How to access controls residing in hubsections in onloadstate method

I am unable to access the controls such as textboxes residing in hubsections in OnLoadState method of the page.
I want to set the TEXT property of textboxes on loading the page. But without access, I can't.
Try Loaded instead:
<HubSection Header="Trailers">
<DataTemplate>
<TextBox Loaded="TextBox_Loaded" />
</DataTemplate>
</HubSection>
And then set the value like below :
private void TextBox_Loaded(object sender, RoutedEventArgs e)
{
var txtBox = (TextBox)sender;
txtBox.Text = "Some Text";
}
Copied from here.

Back button not working when placed in AppBar

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

ApplicationBar not showing up in Windows Phone HTML Template

I have created an application bar in code behind in a new Windows Phone HTML template. Originally the application bar was in xaml but I removed it. I created my application bar like I normally do in the code behind, although in this template for some reason it will not show up. I cannot figure out what the issue is, I have no errors. My code is below. The only thing I did in the XAML of the template is add a pivot control and I made the browser visibility false. My code is below. Any ideas?
XAML
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:Pivot>
<phone:Pivot.TitleTemplate>
<DataTemplate>
<TextBlock Text="APPLICATION NAME">
</DataTemplate>
</phone:Pivot.TitleTemplate>
<phone:PivotItem Header="one">
</phone:PivotItem>
<phone:PivotItem Header="two">
</phone:PivotItem>
</phone:Pivot>
<phone:WebBrowser x:Name="Browser" Visibility="Collapsed"
IsScriptEnabled="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Loaded="Browser_Loaded"
Navigated="Browser_Navigated"
NavigationFailed="Browser_NavigationFailed"
ScriptNotify="Browser_ScriptNotify"/>
<ProgressBar x:Name="PerformanceProgressbar"
VerticalAlignment="Top"
IsIndeterminate="False"
Visibility="Collapsed">
</Grid>
XAML.CS
public MainPage()
{
InitializeComponent();
BuildLocalizedApplicationBar();
}
private void BuildLocalizedApplicationBar()
{
ApplicationBar appbar = new ApplicationBar();
/appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarMenuItem settings = new ApplicationBarMenuItem();
settings.Text = AppResources.MainPage_Settings;
settings.Click += settings_Click;
appbar.MenuItems.Add(settings);
}
You are just creating an object ApplicationBar, but you are not adding it to your Page. Page has a property ApplicationBar which you should set with your created instance of class ApplicationBar.
What would work:
private void BuildLocalizedApplicationBar()
{
ApplicationBar appbar = new ApplicationBar();
/appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarMenuItem settings = new ApplicationBarMenuItem();
settings.Text = AppResources.MainPage_Settings;
settings.Click += settings_Click;
appbar.MenuItems.Add(settings);
this.ApplicationBar = appbar; // or simply ApplicationBar = appbar;
// you can also add Appbar directly = ApplicationBar = new ApplicationBar();
// and then modify via this property
}
Note that you can have many ApplicationBars (objects) and exchange them easily.
Use this code would work:
click here for more details
private void BuildLocalizedApplicationBar()
{
ApplicationBar appbar = new ApplicationBar();
/appbar.Mode = ApplicationBarMode.Minimized;
ApplicationBarMenuItem settings = new ApplicationBarMenuItem();
settings.Text = AppResources.MainPage_Settings;
ApplicationBar.MenuItems.Add(settings );
settings.Click += new EventHandler(settings_Click);
}

How to show list of items on button click?

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 !!

SemanticZoom - How do I keep two ListView controls in selection synch?

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.