* add gtk libs * add new platforms * fix build * GTK Sample * Fix Snackbar wpf * Fix UT * Show actionButton if actionButtonText is not empty * Combine UWP and WPF Co-authored-by: Andrei <andrei.misiukevich@gmail.com> Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
This commit is contained in:
Родитель
3da67ebbb4
Коммит
5908286c4a
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -0,0 +1 @@
|
|||
https://github.com/mono/gtk-sharp
|
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -0,0 +1 @@
|
|||
https://github.com/mono/webkit-sharp
|
Двоичный файл не отображается.
|
@ -0,0 +1,5 @@
|
|||
<configuration>
|
||||
<dllmap dll="webkit-1.0" target="libwebkitgtk-1.0.0.dylib"/>
|
||||
<dllmap dll="webkit-1.0" os="linux" target="libwebkitgtk-1.0.so.0"/>
|
||||
<dllmap dll="webkit-1.0" os="windows" target="libwebkitgtk-1.0-0.dll"/>
|
||||
</configuration>
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using Xamarin.Forms.Platform.GTK;
|
||||
|
||||
namespace Xamarin.CommunityToolkit.Sample.GTK
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main()
|
||||
{
|
||||
Gtk.Application.Init();
|
||||
Forms.Forms.Init();
|
||||
|
||||
var app = new App();
|
||||
var window = new FormsWindow();
|
||||
window.LoadApplication(app);
|
||||
window.SetApplicationTitle("Xamarin Community Toolkit");
|
||||
window.Show();
|
||||
|
||||
Gtk.Application.Run();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Xamarin.CommunityToolkit.Sample.GTK")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Xamarin.CommunityToolkit.Sample.GTK")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1c9105b3-2bb2-4333-9c52-2e0fc99135cf")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,100 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Xamarin.CommunityToolkit.Sample.GTK</RootNamespace>
|
||||
<AssemblyName>Xamarin.CommunityToolkit.Sample.GTK</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\atk-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\gdk-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\glade-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\glib-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="gtk-dotnet, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\gtk-dotnet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\gtk-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\pango-sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Xamarin.Forms">
|
||||
<Version>4.8.0.1269</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Xamarin.Forms.Platform.GTK">
|
||||
<Version>4.8.0.1269</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\XamarinCommunityToolkitSample\Xamarin.CommunityToolkit.Sample.csproj">
|
||||
<Project>{81aade72-d666-4ab0-83d9-8fe366e0755e}</Project>
|
||||
<Name>Xamarin.CommunityToolkit.Sample</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\XamarinCommunityToolkit\Xamarin.CommunityToolkit.csproj">
|
||||
<Project>{b0dcdf81-953d-47da-a7d4-0565339bf07c}</Project>
|
||||
<Name>Xamarin.CommunityToolkit</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -7,11 +7,13 @@ namespace Xamarin.CommunityToolkit.UnitTests.Actions.Snackbar
|
|||
{
|
||||
public class Snackbar_Tests
|
||||
{
|
||||
#if !NETCOREAPP
|
||||
[Fact]
|
||||
public async void PageExtension_DisplaySnackbar_PlatformNotSupportedException()
|
||||
{
|
||||
var page = new ContentPage();
|
||||
await Assert.ThrowsAsync<PlatformNotSupportedException>(() => page.DisplaySnackbar("message"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -10,12 +10,18 @@ namespace Xamarin.CommunityToolkit.UnitTests.Mocks
|
|||
{
|
||||
class MockPlatformServices : IPlatformServices
|
||||
{
|
||||
public string GetHash(string input)
|
||||
=> string.Empty;
|
||||
|
||||
public string GetMD5Hash(string input)
|
||||
=> string.Empty;
|
||||
|
||||
public double GetNamedSize(NamedSize size, Type targetElement, bool useOldSizes)
|
||||
=> 0;
|
||||
|
||||
public Color GetNamedColor(string name)
|
||||
=> Color.Default;
|
||||
|
||||
public void OpenUriAction(Uri uri)
|
||||
{
|
||||
}
|
||||
|
@ -23,6 +29,8 @@ namespace Xamarin.CommunityToolkit.UnitTests.Mocks
|
|||
public bool IsInvokeRequired
|
||||
=> false;
|
||||
|
||||
public OSAppTheme RequestedTheme => OSAppTheme.Unspecified;
|
||||
|
||||
public string RuntimePlatform { get; set; }
|
||||
|
||||
public void BeginInvokeOnMainThread(Action action)
|
||||
|
@ -52,7 +60,7 @@ namespace Xamarin.CommunityToolkit.UnitTests.Mocks
|
|||
}
|
||||
|
||||
public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
|
||||
=> new SizeRequest();
|
||||
=> default;
|
||||
}
|
||||
|
||||
class MockTicker : Ticker
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<TargetFrameworks>netcoreapp3.1;net461</TargetFrameworks>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
#if UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.CommunityToolkit.UI.Views.Helpers
|
||||
{
|
||||
class SnackbarLayout : Grid
|
||||
{
|
||||
public SnackbarLayout(string message, string actionButtonText, Func<Task> action)
|
||||
{
|
||||
RowDefinitions.Add(new RowDefinition());
|
||||
ColumnDefinitions.Add(new ColumnDefinition());
|
||||
ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
|
||||
#if UWP
|
||||
var messageLabel = new TextBlock() { Text = message };
|
||||
#else
|
||||
var messageLabel = new Label() { Content = message };
|
||||
#endif
|
||||
Children.Add(messageLabel);
|
||||
SetRow(messageLabel, 0);
|
||||
SetColumn(messageLabel, 0);
|
||||
if (!string.IsNullOrEmpty(actionButtonText) && action != null)
|
||||
{
|
||||
var button = new Button
|
||||
{
|
||||
Content = actionButtonText,
|
||||
Command = new Forms.Command(async () =>
|
||||
{
|
||||
OnSnackbarActionExecuted?.Invoke();
|
||||
await action();
|
||||
})
|
||||
};
|
||||
Children.Add(button);
|
||||
SetRow(button, 0);
|
||||
SetColumn(button, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public Action OnSnackbarActionExecuted;
|
||||
}
|
||||
}
|
|
@ -1,31 +1,28 @@
|
|||
using Gtk;
|
||||
using System.Linq;
|
||||
using System.Timers;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Platform.GTK;
|
||||
using Xamarin.Forms.Platform.GTK.Extensions;
|
||||
|
||||
namespace Xamarin.CommunityToolkit.Actions.Snackbar
|
||||
namespace Xamarin.CommunityToolkit.UI.Views
|
||||
{
|
||||
public class SnackBar
|
||||
class SnackBar
|
||||
{
|
||||
static Timer snackbarTimer;
|
||||
static bool isSnackBarActive;
|
||||
|
||||
public void Show(Page sender, SnackbarArguments arguments)
|
||||
public void Show(Page page, SnackbarArguments arguments)
|
||||
{
|
||||
if (isSnackBarActive)
|
||||
return;
|
||||
|
||||
isSnackBarActive = true;
|
||||
var platformRender = Platform.GetRenderer(sender) as Widget;
|
||||
var platformRender = Platform.GetRenderer(page) as Widget;
|
||||
var snackBar = GetSnackbarLayout(platformRender, arguments);
|
||||
AddPageContainer(platformRender);
|
||||
((platformRender.Toplevel as Window).Child as VBox).Add(snackBar);
|
||||
(platformRender.Toplevel as Window).Child.ShowAll();
|
||||
snackbarTimer = new Timer(arguments.Duration);
|
||||
snackbarTimer.Elapsed += delegate
|
||||
snackbarTimer.Elapsed += (sender, e) =>
|
||||
{
|
||||
((platformRender.Toplevel as Window).Child as VBox).Remove(snackBar);
|
||||
snackbarTimer.Stop();
|
||||
|
@ -43,9 +40,11 @@ namespace Xamarin.CommunityToolkit.Actions.Snackbar
|
|||
var isActionDialog = !string.IsNullOrEmpty(arguments.ActionButtonText) && arguments.Action != null;
|
||||
if (isActionDialog)
|
||||
{
|
||||
var button = new Gtk.Button();
|
||||
button.Label = arguments.ActionButtonText;
|
||||
button.Clicked += async delegate
|
||||
var button = new Gtk.Button
|
||||
{
|
||||
Label = arguments.ActionButtonText
|
||||
};
|
||||
button.Clicked += async (sender, e) =>
|
||||
{
|
||||
snackbarTimer.Stop();
|
||||
await arguments.Action();
|
||||
|
@ -59,10 +58,7 @@ namespace Xamarin.CommunityToolkit.Actions.Snackbar
|
|||
return snackbarLayout;
|
||||
}
|
||||
|
||||
static Widget GetTopWindowContainer(Widget platformRenderer)
|
||||
{
|
||||
return (platformRenderer.Toplevel as Window).Child;
|
||||
}
|
||||
static Widget GetTopWindowContainer(Widget platformRenderer) => (platformRenderer.Toplevel as Window).Child;
|
||||
|
||||
void AddPageContainer(Widget platformRenderer)
|
||||
{
|
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.UWP;
|
||||
using Xamarin.CommunityToolkit.UI.Views.Helpers;
|
||||
|
||||
namespace Xamarin.CommunityToolkit.UI.Views
|
||||
{
|
||||
|
@ -12,77 +11,54 @@ namespace Xamarin.CommunityToolkit.UI.Views
|
|||
{
|
||||
static DispatcherTimer snackbarTimer;
|
||||
|
||||
T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
|
||||
{
|
||||
var childrenCount = VisualTreeHelper.GetChildrenCount(parent);
|
||||
|
||||
for (var i = 0; i < childrenCount; i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
var controlName = child.GetValue(FrameworkElement.NameProperty) as string;
|
||||
|
||||
if (controlName == name)
|
||||
{
|
||||
return child as T;
|
||||
}
|
||||
|
||||
var control = FindVisualChildByName<T>(child, name);
|
||||
if (control != null)
|
||||
return control;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal void Show(Forms.Page page, SnackbarArguments arguments)
|
||||
{
|
||||
var pageControl = Platform.GetRenderer(page).ContainerElement.Parent as PageControl;
|
||||
var sender = new ExtendedPageControl(pageControl);
|
||||
|
||||
var snackBarLayout = new SnackbarLayout(arguments.Message, arguments.ActionButtonText, arguments.Action);
|
||||
var pageControl = Platform.GetRenderer(page).ContainerElement.Parent;
|
||||
var grid = FindVisualChildByName<Border>(pageControl, "BottomCommandBarArea").Parent as Grid;
|
||||
var snackBarRow = new RowDefinition() { Height = GridLength.Auto };
|
||||
snackbarTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(arguments.Duration) };
|
||||
snackbarTimer.Tick += delegate
|
||||
snackbarTimer.Tick += (sender, e) =>
|
||||
{
|
||||
sender.HideSnackBar();
|
||||
grid.Children.Remove(snackBarLayout);
|
||||
grid.RowDefinitions.Remove(snackBarRow);
|
||||
snackbarTimer.Stop();
|
||||
arguments.SetResult(false);
|
||||
};
|
||||
sender.OnSnackbarActionExecuted += delegate
|
||||
snackBarLayout.OnSnackbarActionExecuted += () =>
|
||||
{
|
||||
sender.HideSnackBar();
|
||||
grid.Children.Remove(snackBarLayout);
|
||||
grid.RowDefinitions.Remove(snackBarRow);
|
||||
snackbarTimer.Stop();
|
||||
arguments.SetResult(true);
|
||||
};
|
||||
snackbarTimer.Start();
|
||||
sender.ShowSnackBar(arguments.Message, arguments.ActionButtonText, arguments.Action);
|
||||
}
|
||||
|
||||
class ExtendedPageControl : ContentControl
|
||||
{
|
||||
public ExtendedPageControl(PageControl pageControl)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SnackbarActionCommandProperty = DependencyProperty.Register("SnackbarActionCommand", typeof(ICommand), typeof(PageControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty SnackbarActionButtonTextProperty = DependencyProperty.Register("SnackbarActionButtonText", typeof(string), typeof(PageControl), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty SnackbarMessageProperty = DependencyProperty.Register("SnackbarMessage", typeof(string), typeof(PageControl), new PropertyMetadata(null));
|
||||
public string SnackbarActionButtonText
|
||||
{
|
||||
get { return (string)GetValue(SnackbarActionButtonTextProperty); }
|
||||
private set { SetValue(SnackbarActionButtonTextProperty, value); }
|
||||
}
|
||||
|
||||
public ICommand SnackbarActionCommand
|
||||
{
|
||||
get { return (ICommand)GetValue(SnackbarActionCommandProperty); }
|
||||
private set { SetValue(SnackbarActionCommandProperty, value); }
|
||||
}
|
||||
|
||||
public string SnackbarMessage
|
||||
{
|
||||
get { return (string)GetValue(SnackbarMessageProperty); }
|
||||
private set { SetValue(SnackbarMessageProperty, value); }
|
||||
}
|
||||
|
||||
public Action OnSnackbarActionExecuted;
|
||||
public void ShowSnackBar(string message, string actionButtonText, Func<Task> action)
|
||||
{
|
||||
SnackbarMessage = message;
|
||||
SnackbarActionButtonText = actionButtonText;
|
||||
if (action != null)
|
||||
{
|
||||
SnackbarActionCommand = new Command(async () =>
|
||||
{
|
||||
OnSnackbarActionExecuted?.Invoke();
|
||||
await action();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void HideSnackBar()
|
||||
{
|
||||
SnackbarMessage = null;
|
||||
SnackbarActionButtonText = null;
|
||||
SnackbarActionCommand = null;
|
||||
}
|
||||
grid.RowDefinitions.Add(snackBarRow);
|
||||
grid.Children.Add(snackBarLayout);
|
||||
Grid.SetRow(snackBarLayout, grid.RowDefinitions.Count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Forms;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.WPF.Controls;
|
||||
using Xamarin.Forms.Platform.WPF.Helpers;
|
||||
using Xamarin.CommunityToolkit.UI.Views.Helpers;
|
||||
|
||||
namespace Xamarin.CommunityToolkit.UI.Views
|
||||
{
|
||||
|
@ -14,75 +12,24 @@ namespace Xamarin.CommunityToolkit.UI.Views
|
|||
|
||||
internal void Show(Page page, SnackbarArguments arguments)
|
||||
{
|
||||
if (System.Windows.Application.Current.MainWindow is MyFormsWindow window)
|
||||
{
|
||||
snackbarTimer = new Timer { Interval = arguments.Duration };
|
||||
snackbarTimer.Tick += delegate
|
||||
{
|
||||
window.HideSnackBar();
|
||||
snackbarTimer.Stop();
|
||||
arguments.SetResult(false);
|
||||
};
|
||||
window.OnSnackbarActionExecuted += delegate
|
||||
{
|
||||
window.HideSnackBar();
|
||||
snackbarTimer.Stop();
|
||||
arguments.SetResult(true);
|
||||
};
|
||||
snackbarTimer.Start();
|
||||
window.ShowSnackBar(arguments.Message, arguments.ActionButtonText, arguments.Action);
|
||||
}
|
||||
else
|
||||
var formsAppBar = System.Windows.Application.Current.MainWindow.FindChild<FormsAppBar>("PART_BottomAppBar");
|
||||
var currentContent = formsAppBar.Content;
|
||||
var snackBar = new SnackbarLayout(arguments.Message, arguments.ActionButtonText, arguments.Action);
|
||||
snackbarTimer = new Timer { Interval = arguments.Duration };
|
||||
snackbarTimer.Tick += (sender, e) =>
|
||||
{
|
||||
formsAppBar.Content = currentContent;
|
||||
snackbarTimer.Stop();
|
||||
arguments.SetResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
class MyFormsWindow : FormsWindow
|
||||
{
|
||||
public static readonly DependencyProperty SnackbarActionCommandProperty = DependencyProperty.Register("SnackbarActionCommand", typeof(ICommand), typeof(FormsWindow));
|
||||
public static readonly DependencyProperty SnackbarActionButtonTextProperty = DependencyProperty.Register("SnackbarActionButtonText", typeof(string), typeof(FormsWindow));
|
||||
public static readonly DependencyProperty SnackbarMessageProperty = DependencyProperty.Register("SnackbarMessage", typeof(string), typeof(FormsWindow));
|
||||
|
||||
public string SnackbarActionButtonText
|
||||
};
|
||||
snackBar.OnSnackbarActionExecuted += () =>
|
||||
{
|
||||
get { return (string)GetValue(SnackbarActionButtonTextProperty); }
|
||||
private set { SetValue(SnackbarActionButtonTextProperty, value); }
|
||||
}
|
||||
|
||||
public ICommand SnackbarActionCommand
|
||||
{
|
||||
get { return (ICommand)GetValue(SnackbarActionCommandProperty); }
|
||||
private set { SetValue(SnackbarActionCommandProperty, value); }
|
||||
}
|
||||
|
||||
public string SnackbarMessage
|
||||
{
|
||||
get { return (string)GetValue(SnackbarMessageProperty); }
|
||||
private set { SetValue(SnackbarMessageProperty, value); }
|
||||
}
|
||||
public Action OnSnackbarActionExecuted;
|
||||
public void ShowSnackBar(string message, string actionButtonText, Func<Task> action)
|
||||
{
|
||||
SnackbarMessage = message;
|
||||
SnackbarActionButtonText = actionButtonText;
|
||||
if (action != null)
|
||||
{
|
||||
SnackbarActionCommand = new Command(async () =>
|
||||
{
|
||||
OnSnackbarActionExecuted?.Invoke();
|
||||
await action();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void HideSnackBar()
|
||||
{
|
||||
SnackbarMessage = null;
|
||||
SnackbarActionButtonText = null;
|
||||
SnackbarActionCommand = null;
|
||||
}
|
||||
formsAppBar.Content = currentContent;
|
||||
snackbarTimer.Stop();
|
||||
arguments.SetResult(true);
|
||||
};
|
||||
snackbarTimer.Start();
|
||||
formsAppBar.Content = snackBar;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard1.0;netstandard2.0;netstandard2.1;Xamarin.iOS10;MonoAndroid90;MonoAndroid10.0;Xamarin.TVOS10;Xamarin.WatchOS10;Xamarin.Mac20;tizen40</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);uap10.0.17763;net472</TargetFrameworks>
|
||||
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);uap10.0.17763;netcoreapp3.1;net472;net471</TargetFrameworks>
|
||||
<AssemblyName>Xamarin.CommunityToolkit</AssemblyName>
|
||||
<RootNamespace>Xamarin.CommunityToolkit</RootNamespace>
|
||||
<PackageId>Xamarin.CommunityToolkit</PackageId>
|
||||
|
@ -52,13 +52,20 @@
|
|||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netcoreapp')) ">
|
||||
<UseWPF>true</UseWPF>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" $(TargetFramework.StartsWith('uap10.0')) ">
|
||||
<DefineConstants>UWP</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)'=='Debug' ">
|
||||
<!-- Manage Xamarin.Forms version for development -->
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.5.0.356" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.7.0.968" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)'=='Release' ">
|
||||
<!-- Manage Xamarin.Forms version for distribution -->
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.5.0.356" />
|
||||
<PackageReference Include="Xamarin.Forms" Version="4.7.0.968" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -149,7 +156,62 @@
|
|||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.5.0.356" />
|
||||
<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.7.0.968" />
|
||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(TargetFramework.StartsWith('netcoreapp')) ">
|
||||
<Compile Include="**\*.wpf.cs" />
|
||||
<Compile Include="**\*.wpf.*.cs" />
|
||||
<Compile Remove="**\Snackbar.shared.cs" />
|
||||
<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.7.0.968" />
|
||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" $(TargetFramework.StartsWith('net471')) ">
|
||||
<Compile Include="**\*.gtk.cs" />
|
||||
<Compile Include="**\*.gtk.*.cs" />
|
||||
<Compile Remove="**\Snackbar.shared.cs" />
|
||||
<PackageReference Include="Xamarin.Forms.Platform.GTK" Version="4.7.0.968" />
|
||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||
<Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\atk-sharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\gdk-sharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\glade-sharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\glib-sharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="gtk-dotnet, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\gtk-dotnet.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\gtk-sharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Libs\gtk-sharp\gtk-sharp-2.0\pango-sharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\Snackbar\Helpers\WPF\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -123,8 +123,12 @@
|
|||
<BundleResource Include="Resources\xamarin_logo%402x.png" />
|
||||
<BundleResource Include="Resources\xamarin_logo%403x.png" />
|
||||
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />
|
||||
<ImageAsset Include="Assets.xcassets\LauncherIcon.imageset\Contents.json" />
|
||||
<ImageAsset Include="Assets.xcassets\LauncherIcon.imageset\LauncherIcon.pdf" />
|
||||
<ImageAsset Include="Assets.xcassets\LauncherIcon.imageset\Contents.json">
|
||||
<Visible>false</Visible>
|
||||
</ImageAsset>
|
||||
<ImageAsset Include="Assets.xcassets\LauncherIcon.imageset\LauncherIcon.pdf">
|
||||
<Visible>false</Visible>
|
||||
</ImageAsset>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
|
|
|
@ -12,7 +12,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit",
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{47DFE508-04F1-433D-8C55-0C1ACD033573}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.UnitTests", "XamarinCommunityToolkit.UnitTests\Xamarin.CommunityToolkit.UnitTests.csproj", "{54B7812B-45A5-4FE2-9CEA-C5F17D65BDE9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.CommunityToolkit.UnitTests", "XamarinCommunityToolkit.UnitTests\Xamarin.CommunityToolkit.UnitTests.csproj", "{54B7812B-45A5-4FE2-9CEA-C5F17D65BDE9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.Sample.UWP", "XamarinCommunityToolkitSample.UWP\Xamarin.CommunityToolkit.Sample.UWP.csproj", "{91C748B4-E9ED-4543-880A-26747B03DE3A}"
|
||||
EndProject
|
||||
|
@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.Sample.WPF", "Xamarin.CommunityToolkit.Sample.WPF\Xamarin.CommunityToolkit.Sample.WPF.csproj", "{C4D6CD2D-8DF4-4D46-936C-1AB31C87B5EA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.CommunityToolkit.Sample.GTK", "Xamarin.CommunityToolkit.Sample.GTK\Xamarin.CommunityToolkit.Sample.GTK.csproj", "{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -231,6 +233,30 @@ Global
|
|||
{C4D6CD2D-8DF4-4D46-936C-1AB31C87B5EA}.Release|x64.Build.0 = Release|Any CPU
|
||||
{C4D6CD2D-8DF4-4D46-936C-1AB31C87B5EA}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{C4D6CD2D-8DF4-4D46-936C-1AB31C87B5EA}.Release|x86.Build.0 = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|ARM.ActiveCfg = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|ARM.Build.0 = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|ARM.ActiveCfg = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|ARM.Build.0 = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|iPhone.Build.0 = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|x64.Build.0 = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{1C9105B3-2BB2-4333-9C52-2E0FC99135CF}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
Загрузка…
Ссылка в новой задаче