5
// Alan McGovern <alan@xamarin.com>
7
// Copyright (c) 2012 Xamarin, Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using System.Windows.Media;
31
namespace Xwt.WPFBackend
33
public class PopoverBackend : IPopoverBackend
35
public Xwt.Popover.Position ActualPosition {
39
System.Windows.Controls.Border Border {
43
IPopoverEventSink EventSink {
51
System.Windows.Controls.Primitives.Popup NativeWidget {
55
public PopoverBackend ()
57
Border = new System.Windows.Controls.Border {
58
BorderBrush = Brushes.Black,
59
CornerRadius = new System.Windows.CornerRadius (15),
60
Padding = new System.Windows.Thickness (15),
61
BorderThickness = new System.Windows.Thickness (1)
64
NativeWidget = new System.Windows.Controls.Primitives.Popup {
65
AllowsTransparency = true,
67
Placement = System.Windows.Controls.Primitives.PlacementMode.Custom,
69
Margin = new System.Windows.Thickness (10),
72
NativeWidget.CustomPopupPlacementCallback = (popupSize, targetSize, offset) => {
73
var location = new System.Windows.Point (targetSize.Width / 2 - popupSize.Width / 2, 0);
74
if (ActualPosition == Popover.Position.Top)
75
location.Y = targetSize.Height;
77
location.Y = -popupSize.Height;
80
new System.Windows.Controls.Primitives.CustomPopupPlacement (location, System.Windows.Controls.Primitives.PopupPrimaryAxis.Horizontal)
85
public void Initialize (IPopoverEventSink sink)
90
public void InitializeBackend (object frontend)
92
Frontend = (Popover) frontend;
95
public void EnableEvent (object eventId)
97
if (eventId is PopoverEvent)
98
if ((PopoverEvent)eventId == PopoverEvent.Closed)
99
NativeWidget.Closed +=new EventHandler(NativeWidget_Closed);
102
public void DisableEvent (object eventId)
104
if (eventId is PopoverEvent)
105
if ((PopoverEvent) eventId == PopoverEvent.Closed)
106
NativeWidget.Closed += new EventHandler (NativeWidget_Closed);
109
public void Show (Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Rectangle positionRect, Widget child)
111
ActualPosition = orientation;
112
Border.Child = (System.Windows.FrameworkElement) Xwt.Engine.WidgetRegistry.GetNativeWidget (child);
113
NativeWidget.PlacementTarget =(System.Windows.FrameworkElement) Xwt.Engine.WidgetRegistry.GetNativeWidget (reference);
114
NativeWidget.IsOpen = true;
117
void NativeWidget_Closed (object sender, EventArgs e)
119
EventSink.OnClosed ();
124
NativeWidget.IsOpen = false;
127
public void Dispose ()
129
if (NativeWidget != null)
130
NativeWidget.Closed -= NativeWidget_Closed;
b'\\ No newline at end of file'