Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Bloxstrap/Resources/CustomBootstrapperSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,17 @@
"StretchDirection": "StretchDirection",
"Source": "ImageSource",
"IsAnimated": "bool",
"RepeatBehavior": "RepeatBehavior"
"RepeatBehavior": "RepeatBehavior"
}
},
"MediaElement": {
"SuperClass": "FrameworkElement",
"IsCreatable": true,
"Attributes": {
"Stretch": "Stretch",
"StretchDirection": "StretchDirection",
"Source": "Uri",
"Looped": "bool"
}
},
"Grid": {
Expand Down Expand Up @@ -322,6 +332,7 @@
"Rect": {},
"Point": {},
"CornerRadius": {},
"Uri": {},
"Brush": { "CanHaveElement": true },
"Color": {},
"ImageSource": {},
Expand Down
1 change: 1 addition & 0 deletions Bloxstrap/UI/Elements/Bootstrapper/CustomDialog.Creator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private class DummyFrameworkElement : FrameworkElement { }
["TextBlock"] = HandleXmlElement_TextBlock,
["MarkdownTextBlock"] = HandleXmlElement_MarkdownTextBlock,
["Image"] = HandleXmlElement_Image,
["MediaElement"] = HandleXmlElement_MediaElement,
["Grid"] = HandleXmlElement_Grid,
["StackPanel"] = HandleXmlElement_StackPanel,
["Border"] = HandleXmlElement_Border,
Expand Down
29 changes: 29 additions & 0 deletions Bloxstrap/UI/Elements/Bootstrapper/CustomDialog.Elements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,35 @@ private static UIElement HandleXmlElement_Image(CustomDialog dialog, XElement xm
return image;
}

private static UIElement HandleXmlElement_MediaElement(CustomDialog dialog, XElement xmlElement)
{
var media = new MediaElement();
HandleXmlElement_FrameworkElement(dialog, media, xmlElement);

RenderOptions.SetBitmapScalingMode(media, BitmapScalingMode.HighQuality);

// should behaviour be modifiable? (except unloadedbehavior ig)
media.LoadedBehavior = MediaState.Play;
media.UnloadedBehavior = MediaState.Close;

media.Volume = 0;

media.Stretch = ParseXmlAttribute<Stretch>(xmlElement, "Stretch", Stretch.Uniform);
media.StretchDirection = ParseXmlAttribute<StretchDirection>(xmlElement, "StretchDirection", StretchDirection.Both);

media.Source = GetMediaSourceData(dialog, "Source", xmlElement);

if (ParseXmlAttribute<bool>(xmlElement, "Looped", false))
{
media.MediaEnded += (Sender, e) =>
{
media.Position = TimeSpan.Zero;
};
}

return media;
}

private static RowDefinition HandleXmlElement_RowDefinition(CustomDialog dialog, XElement xmlElement)
{
var rowDefinition = new RowDefinition();
Expand Down
18 changes: 18 additions & 0 deletions Bloxstrap/UI/Elements/Bootstrapper/CustomDialog.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ private static GetImageSourceDataResult GetImageSourceData(CustomDialog dialog,
return new GetImageSourceDataResult { Uri = result };
}

private static Uri GetMediaSourceData(CustomDialog dialog, string name, XElement xmlElement)
{
string path = GetXmlAttribute(xmlElement, name);

path = GetFullPath(dialog, path)!;

if (!Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out Uri? result))
throw new CustomThemeException("CustomTheme.Errors.ElementAttributeParseError", xmlElement.Name, name, "Uri");

if (result == null)
throw new CustomThemeException("CustomTheme.Errors.ElementAttributeParseErrorNull", xmlElement.Name, name, "Uri");

if (result.Scheme != "file")
throw new CustomThemeException("CustomTheme.Errors.ElementAttributeBlacklistedUriScheme", xmlElement.Name, name, result.Scheme);

return result;
}

private static object? GetContentFromXElement(CustomDialog dialog, XElement xmlElement)
{
var contentAttr = xmlElement.Attribute("Content");
Expand Down