Skip to content

Commit 32e6f48

Browse files
committed
Added Relative view support
1 parent 46e5b17 commit 32e6f48

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

maui/src/Calendar/Model/SfCalendar.cs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,20 @@ public partial class SfCalendar
605605
CalendarRelativePosition.AlignTop,
606606
propertyChanged: OnRelativePositionChanged);
607607

608+
/// <summary>
609+
/// Identifies the <see cref="RelativeView"/> dependency property.
610+
/// </summary>
611+
/// <value>
612+
/// The identifier for <see cref="RelativeView"/> dependency property.
613+
/// </value>
614+
public static readonly BindableProperty RelativeViewProperty =
615+
BindableProperty.Create(
616+
nameof(RelativeView),
617+
typeof(View),
618+
typeof(SfCalendar),
619+
null,
620+
propertyChanged: OnRelativeViewChanged);
621+
608622
#if WINDOWS
609623
/// <summary>
610624
/// Identifies the <see cref="FlowDirectionProperty"/> dependency property.
@@ -2265,6 +2279,47 @@ public CalendarRelativePosition RelativePosition
22652279
set { SetValue(RelativePositionProperty, value); }
22662280
}
22672281

2282+
/// <summary>
2283+
/// Gets or sets the view relative to which the calendar dialog should be displayed based on the RelativePosition.
2284+
/// <seealso cref="SfCalendar.RelativePosition"/>
2285+
/// </summary>
2286+
/// <remarks>
2287+
/// It is only applicable for RelativeDialog mode. If no relative view is given, the calendar will be set as the relative view.
2288+
/// </remarks>
2289+
/// <example>
2290+
/// The following code demonstrates, how to use the RelativeView property in the calendar
2291+
/// #[XAML](#tab/tabid-1)
2292+
/// <code Lang="XAML"><![CDATA[
2293+
/// <Grid WidthRequest="500">
2294+
/// <calendar:SfCalendar x:Name="calendar"
2295+
/// Mode="RelativeDialog"
2296+
/// RelativePosition="AlignToRightOf"
2297+
/// RelativeView="{x:Reference calendarButton}">
2298+
/// </calendar:SfCalendar>
2299+
/// <Button Text="Open calendar"
2300+
/// x:Name="calendarButton"
2301+
/// Clicked="Button_Clicked"
2302+
/// HorizontalOptions="Center"
2303+
/// VerticalOptions="Center"
2304+
/// HeightRequest="50"
2305+
/// WidthRequest="150">
2306+
/// </Button>
2307+
/// </Grid>
2308+
/// ]]></code>
2309+
/// # [C#](#tab/tabid-2)
2310+
/// <code Lang="C#"><![CDATA[
2311+
/// private void Button_Clicked(object sender, System.EventArgs e)
2312+
/// {
2313+
/// this.calendar.IsOpen = true;
2314+
/// }
2315+
/// ]]></code>
2316+
/// </example>
2317+
public View RelativeView
2318+
{
2319+
get { return (View)GetValue(RelativeViewProperty); }
2320+
set { SetValue(RelativeViewProperty, value); }
2321+
}
2322+
22682323
//// TODO: Workaround for RTL (Right-to-Left) layout issue - The coordinate points are not calculated correctly in RTL layouts,
22692324
//// causing incorrect positioning. This flag helps to apply RTL-specific adjustments.
22702325
#if WINDOWS
@@ -2497,7 +2552,7 @@ protected override void OnPropertyChanged(string? propertyName = null)
24972552
CloseCalendarPopup();
24982553
}
24992554
}
2500-
else if(propertyName == "FlowDirection")
2555+
else if (propertyName == "FlowDirection")
25012556
{
25022557
if (FlowDirection == FlowDirection.RightToLeft)
25032558
{
@@ -3519,6 +3574,26 @@ static void OnRelativePositionChanged(BindableObject bindable, object oldValue,
35193574
}
35203575
}
35213576

3577+
/// <summary>
3578+
/// Called when <see cref="RelativeView"/> property changed.
3579+
/// </summary>
3580+
/// <param name="bindable">The bindable.</param>
3581+
/// <param name="oldValue">The old value.</param>
3582+
/// <param name="newValue">The new value.</param>
3583+
static void OnRelativeViewChanged(BindableObject bindable, object oldValue, object newValue)
3584+
{
3585+
SfCalendar? calendar = bindable as SfCalendar;
3586+
if (calendar == null)
3587+
{
3588+
return;
3589+
}
3590+
3591+
if (calendar.IsOpen && calendar.Mode == CalendarMode.RelativeDialog && calendar.RelativeView != null)
3592+
{
3593+
calendar.ShowPopup();
3594+
}
3595+
}
3596+
35223597
#if WINDOWS
35233598
/// <summary>
35243599
/// Method invoke when flow direction property changed.

maui/src/Calendar/SfCalendar.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,14 @@ void ShowPopup()
19731973

19741974
if (Mode == CalendarMode.RelativeDialog)
19751975
{
1976-
ShowRelativeToView(this, RelativePosition);
1976+
if (RelativeView != null)
1977+
{
1978+
ShowRelativeToView(RelativeView, RelativePosition);
1979+
}
1980+
else
1981+
{
1982+
ShowRelativeToView(this, RelativePosition);
1983+
}
19771984
}
19781985
else
19791986
{
@@ -2203,7 +2210,7 @@ protected override Size MeasureContent(double widthConstraint, double heightCons
22032210
{
22042211
return _availableSize;
22052212
}
2206-
#endif
2213+
#endif
22072214

22082215
if (_layout.Children.Count == 0)
22092216
{
@@ -2250,7 +2257,7 @@ protected override void OnDraw(ICanvas canvas, RectF dirtyRect)
22502257
{
22512258
currentClip = new RoundRectangleGeometry(CornerRadius, rectangle);
22522259
}
2253-
#endif
2260+
#endif
22542261
RoundRectangleGeometry? previousClip = null;
22552262
if (Clip != null && Clip is RoundRectangleGeometry)
22562263
{

0 commit comments

Comments
 (0)