amarmesic / windows-phone-navigation-drawer Goto Github PK
View Code? Open in Web Editor NEWNavigation Drawer Layout for Windows Phone 8.1
Navigation Drawer Layout for Windows Phone 8.1
First of all this is a very cool library. Thank you very much!
I found an issue:
If you tap on the main panel to close the drawer and then tap on the menu icon to open it again it will not work. You have to tap the menu icon twice in this case to make it work.
I have a relatively big Windows Phone 8.1 app and I added the navigation drawer to it. I have a problem with it though. When navigation trough the app, after going a few pages, the app just exists. No exception, no crash, just exit (has exited with code 0 (0x0)
)
Like the title says, creating any grid after the MainFragment grid crashes the app whenever you click an article from the MainFragment content. Therefore the "ListFragment" grid can not be successfully implemented. Here is the code :
--------------------------------------------MAINPAGE XAML---------------------------------
<Page
xmlns:drawerLayout="using:DrawerLayout"
x:Class="AppStudio.Views.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppStudio.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:AppStudio.ViewModels"
mc:Ignorable="d">
<Grid x:Name="RootLayout" Margin="0,-26.667,0,-0.333">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Title Bar -->
<Grid x:Name="TitleBar" Background="#ffffff" Grid.Row ="0" Height="60" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Margin="0,8,0,0" x:Name="DrawerIcon" Grid.Column="0" Source="/Assets/kaltert.png" HorizontalAlignment="Left" Tapped="DrawerIcon_Tapped" />
<Image Margin="0,2,55,2" x:Name="Logo" Grid.Column="1" Source="/Assets/tmheaderkaltert.png" HorizontalAlignment="Center" />
</Grid>
<drawerLayout:DrawerLayout Grid.Row="1" x:Name="DrawerLayout">
<Grid x:Name="MainFragment" Background="#ffffff">
<Hub x:Name="Container" Margin="0,28,0,0" Background="{StaticResource AppBackground}" DataContext="{Binding}" SectionsInViewChanged="OnSectionsInViewChanged">
<HubSection x:Name="LajmetSection" Padding="0,-30,20,0" Width="400" DataContext="{Binding MainViewModel.LajmetModel}"
d:DataContext="{d:DesignData Source=/Assets/Data/LajmetDataSource.json, Type=vm:LajmetViewModel, IsDesignTimeCreatable=true}"
ContentTemplate="{StaticResource LajmetList}" IsHeaderInteractive="{Binding HasMoreItems}" />
</Hub>
</Grid>
-----------ANY GRID I ADD AFTER THIS LINE CRASHES THE APP LIKE THE "LISTFRAGMENT FOR EXAMPLE"--------------------------------------
<Grid x:Name="ListFragment" Background="#141e28">
<ListView x:Name="ListMenuItems">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="23" Foreground="White" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
-----------------------------------------------------------------------------------------------------------------------------------
</drawerLayout:DrawerLayout>
</Grid>
</Page>
_____________________________________________________ ________________________________________________________________
_____________________________________________________C# Code here:__________________________________________________________
using System;
using System.Linq;
using System.Net.NetworkInformation;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Background;
using AppStudio.Services;
using AppStudio.ViewModels;
namespace AppStudio.Views
{
public sealed partial class MainPage : Page
{
private MainViewModel _mainViewModel = null;
private NavigationHelper _navigationHelper;
private DataTransferManager _dataTransferManager;
public MainPage()
{
this.NavigationCacheMode = NavigationCacheMode.Required;
this.InitializeComponent();
//drawerlayout
DrawerLayout.InitializeDrawerLayout();
string[] menuItems = new string[5] { "Item1", "Item2", "Item3", "Item4", "Item5" };
// ListMenuItems.ItemsSource = menuItems.ToList();
this.NavigationCacheMode = NavigationCacheMode.Required;
_navigationHelper = new NavigationHelper(this);
_mainViewModel = _mainViewModel ?? new MainViewModel();
DataContext = this;
ApplicationView.GetForCurrentView().
SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
}
public MainViewModel MainViewModel
{
get { return _mainViewModel; }
}
private void DrawerIcon_Tapped(object sender, TappedRoutedEventArgs e)
{
if (DrawerLayout.IsDrawerOpen)
DrawerLayout.CloseDrawer();
else
DrawerLayout.OpenDrawer();
}
/// <summary>
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
/// </summary>
public NavigationHelper NavigationHelper
{
get { return _navigationHelper; }
}
private void OnSectionsInViewChanged(object sender, SectionsInViewChangedEventArgs e)
{
var selectedSection = Container.SectionsInView.FirstOrDefault();
if (selectedSection != null)
{
MainViewModel.SelectedItem = selectedSection.DataContext as ViewModelBase;
}
}
#region NavigationHelper registration
/// The methods provided in this section are simply used to allow
/// NavigationHelper to respond to the page's navigation methods.
///
/// Page specific logic should be placed in event handlers for the
/// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
/// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
/// The navigation parameter is available in the LoadState method
/// in addition to page state preserved during an earlier session.
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
_dataTransferManager = DataTransferManager.GetForCurrentView();
_dataTransferManager.DataRequested += OnDataRequested;
_navigationHelper.OnNavigatedTo(e);
await MainViewModel.LoadDataAsync();
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
_navigationHelper.OnNavigatedFrom(e);
_dataTransferManager.DataRequested -= OnDataRequested;
}
#endregion
private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
var viewModel = MainViewModel.SelectedItem;
if (viewModel != null)
{
viewModel.GetShareContent(args.Request);
}
}
}
}
__________________________________________________________________________________
----------------------------------AppDetailPage XAML------------------------------
__________________________________________________________________________________
<Page
x:Class="AppStudio.Views.LajmetDetail"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppStudio.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:AppStudio.ViewModels"
mc:Ignorable="d">
<Grid Background="{StaticResource AppBackground}"
DataContext="{Binding LajmetModel}"
d:DataContext="{d:DesignData Source=/Assets/Data/LajmetDataSource.json, Type=vm:LajmetViewModel, IsDesignTimeCreatable=true}" Margin="0,-26.667,0,-0.333">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<FlipView x:Name="Flip" Grid.Row="0" Padding="0,10,0,0" AutomationProperties.AutomationId="ItemsFlipView" AutomationProperties.Name="Item Details" TabIndex="1"
ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource Lajmet1DetailDetail}"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"/>
</Grid>
<Page.BottomAppBar>
<CommandBar ClosedDisplayMode="Minimal" Background="{StaticResource AppBarBackground}" Foreground="{StaticResource AppBarForeground}">
<AppBarButton x:Uid="RefreshButton" Icon="Refresh" DataContext="{Binding LajmetModel}" Command="{Binding RefreshCommand}" Visibility="{Binding RefreshVisibility}"/>
<AppBarButton x:Uid="GoToSourceButton" Icon="Globe" DataContext="{Binding LajmetModel}" Command="{Binding GoToSourceCommand}" Visibility="{Binding GoToSourceVisibility}"/>
</CommandBar>
</Page.BottomAppBar>
</Page>
_____________________________________________________ ________________________________________________________________
_____________________________________________________C# Code here:__________________________________________________________
using AppStudio.Services;
using AppStudio.ViewModels;
using Windows.ApplicationModel.DataTransfer;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
namespace AppStudio.Views
{
public sealed partial class LajmetDetail : Page
{
private NavigationHelper _navigationHelper;
private DataTransferManager _dataTransferManager;
public LajmetDetail()
{
this.InitializeComponent();
_navigationHelper = new NavigationHelper(this);
LajmetModel = new LajmetViewModel();
}
public LajmetViewModel LajmetModel { get; private set; }
public NavigationHelper NavigationHelper
{
get { return _navigationHelper; }
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
_dataTransferManager = DataTransferManager.GetForCurrentView();
_dataTransferManager.DataRequested += OnDataRequested;
_navigationHelper.OnNavigatedTo(e);
if (LajmetModel != null)
{
await LajmetModel.LoadItemsAsync();
LajmetModel.SelectItem(e.Parameter);
LajmetModel.ViewType = ViewTypes.Detail;
}
DataContext = this;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
_navigationHelper.OnNavigatedFrom(e);
_dataTransferManager.DataRequested -= OnDataRequested;
}
private void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
if (LajmetModel != null)
{
LajmetModel.GetShareContent(args.Request);
}
}
}
}
I have the exact same isse I cannot open a drawer with a listview has anyone come across a fix for this as I dont understand the above fix?.
This is implemented but it doesn't work for me. Calling open drawer in code works. But manipulation on the main fragment doesn't. What could be the cause?
Edit:
I think I know the cause. I have listviews on both fragments of the drawerlayout control. I think the manipulation events are hijacked by the listviews, and the underlying grids don't get notified of the events. Is there a fix to this?
In order to access the current IsDrawerOpen state, I had to Databind it into my ViewModel.
But the IsDrawerOpen was implemented as a normal Property, thus TwoWay Databinding failed with an exception.
To allow TwoWay DataBinding in XAML it is required to implement an Dependency Property. I have added it.
I am not very familiar with git pull requests, so I just created a patch file (it's a very small change anyways)
The Patch file can be found https://gist.github.com/TsengSR/6581d1ccc6eed5de3579
Then I can DataBind my property to my ViewModel and my ViewModel is always aware then the drawer state changes
IsDrawerOpen="{Binding Mode=TwoWay, Path=IsOpen, UpdateSourceTrigger=PropertyChanged}"
I needed this to make it work with Prism, as Prism has it's own Navigation Manager and was closing my Page which contained the navigation, when the drawer was opened, which was very undesired.
As the title say, if you slide the open drawer to the right, it will jump to some crazy animation and close the drawer, can you test this behavior ?
Awesome lib, but needs windows 10 support
Hello. How use this control with mvvm (Prism)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.