Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This change includes the addition of a few new features to UIButton. #1920

Merged
merged 5 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion Frameworks/UIKit.Xaml/Button.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<ControlTemplate TargetType="Button" x:Name="UIKitButtonControlTemplate">
<Canvas x:Name="contentCanvas" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Background="{TemplateBinding Background}">
<Image x:Name="buttonImage" Stretch="Fill" IsHitTestVisible="False" />
<TextBlock x:Name="buttonText" MaxLines="1" TextTrimming="CharacterEllipsis" IsHitTestVisible="False"/>
<Border x:Name="buttonBorder" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" />
<!--TODO: This hits a XamlParseException in some apps; tracked as #1919.
<local:Label x:Name="buttonLabel" IsHitTestVisible="False"/>-->
</Canvas>
</ControlTemplate>
</Button.Template>
Expand Down
21 changes: 7 additions & 14 deletions Frameworks/UIKit.Xaml/Button.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ Windows::Foundation::Size Button::ArrangeOverride(Windows::Foundation::Size fina

void Button::OnApplyTemplate() {
// Call GetTemplateChild to grab references to UIElements in our custom control template
_textBlock = safe_cast<TextBlock^>(GetTemplateChild("buttonText"));
_image = safe_cast<Image^>(GetTemplateChild("buttonImage"));
_border = safe_cast<Border^>(GetTemplateChild("buttonBorder"));
_contentCanvas = safe_cast<Canvas^>(GetTemplateChild(L"contentCanvas"));
}

Expand All @@ -204,28 +204,21 @@ UIKIT_XAML_EXPORT void XamlRemoveLayoutEvent(const ComPtr<IInspectable>& inspect
button->RemoveLayoutEvent();
}

UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(const ComPtr<IInspectable>& inspectableButton,
const ComPtr<IInspectable>& inspectableText,
UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(
const ComPtr<IInspectable>& inspectableButton,
const ComPtr<IInspectable>& inspectableButtonImage,
const ComPtr<IInspectable>& inspectableTitleColor) {

const ComPtr<IInspectable>& inspectableBorderBackgroundBrush) {
auto button = safe_cast<UIKit::Xaml::Button^>(reinterpret_cast<Platform::Object^>(inspectableButton.Get()));
auto title = safe_cast<Platform::String^>(reinterpret_cast<Platform::Object^>(inspectableText.Get()));
auto titleColor = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableTitleColor.Get()));
if (!titleColor) {
titleColor = UIKit::Xaml::GetDefaultWhiteForegroundBrush();
}

// Set the Textblock's title and Foreground Brush color
button->_textBlock->Text = title;
button->_textBlock->Foreground = titleColor;

// Set the Button's Image
auto image = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableButtonImage.Get()));
if (image) {
ImageBrush^ imageBrush = safe_cast<ImageBrush^>(image);
button->_image->Source = safe_cast<BitmapSource^>(imageBrush->ImageSource);
}

// Set the border background brush (if any)
button->_border->Background = safe_cast<Brush^>(reinterpret_cast<Platform::Object^>(inspectableBorderBackgroundBrush.Get()));
}

UIKIT_XAML_EXPORT void XamlHookButtonPointerEvents(
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit.Xaml/Button.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public ref class Button sealed : public Private::CoreAnimation::ILayer {
void RemovePointerEvents();
void RemoveLayoutEvent();

Windows::UI::Xaml::Controls::TextBlock^ _textBlock;
Windows::UI::Xaml::Controls::Image^ _image;
Windows::UI::Xaml::Controls::Border^ _border;

private:
Windows::UI::Xaml::Controls::Canvas^ _contentCanvas; // Contains pre-canned button content, as well as any sublayers added by CoreAnimation.
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit.Xaml/Layer.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ref class Layer sealed : public ILayer {
}

// Allows arbitrary framework elements to opt-into hosting sublayers
static property Windows::UI::Xaml::DependencyProperty^ SublayerCanvasProperty {
static property Windows::UI::Xaml::DependencyProperty^ SublayerCanvasProperty {
Windows::UI::Xaml::DependencyProperty^ get();
}

Expand Down
3 changes: 1 addition & 2 deletions Frameworks/UIKit.Xaml/ObjCXamlControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ enum ControlStates { ControlStateNormal = 0, ControlStateHighlighted = 1 << 0, C
UIKIT_XAML_EXPORT void XamlCreateButton(IInspectable** created);

UIKIT_XAML_EXPORT void XamlButtonApplyVisuals(const Microsoft::WRL::ComPtr<IInspectable>& inspectableButton,
const Microsoft::WRL::ComPtr<IInspectable>& inspectableText,
const Microsoft::WRL::ComPtr<IInspectable>& inspectableImage,
const Microsoft::WRL::ComPtr<IInspectable>& inspectableTitleColor);
const Microsoft::WRL::ComPtr<IInspectable>& inspectableBorderBackgroundBrush);

// Hooks pointer events on a UIKit::Button passed in as IInspectable
UIKIT_XAML_EXPORT void XamlHookButtonPointerEvents(const Microsoft::WRL::ComPtr<IInspectable>& inspectableButton,
Expand Down
Loading