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

Support of XamlHost / XamlIslands #205

Closed
evilbaschdi opened this issue May 18, 2020 · 4 comments
Closed

Support of XamlHost / XamlIslands #205

evilbaschdi opened this issue May 18, 2020 · 4 comments

Comments

@evilbaschdi
Copy link

I played around with XamlHost a little bit.
The difference between "normal" WPF or UWP code ist that it's only possible to define the WindowsXamlHost it self and an "InitialTypeName" to be "Windows.UI.Xaml.Controls.Button" inside the xaml. All other stuff has to be done in the code behind - what is not so nice.

So I usually have had an icon next to my button caption as a content. So I added a StackPanel to the button and hostet an icon and a TextBlock inside the StackPanel.
Now with the current state of implementation of XamlIslands I have to do that all manually.

  • Cast the Control to Button => done
  • Add a StackPanel to it => done
  • Add a TextBlock to it => done
  • Add an icon to it ... That is where my problem begins
    I already tried to host the PackIcon inside the Windows.UI.Xaml.Controls.StackPanel that ends up an some casting errors.
    Lastly I added a new Image, set Binding.Source to my PackIcon and failed while setting the bindings converter to PackIconMaterialKindToImageConverter.

So do you have plans or already working code examples on how to host IconPacks inside Windows.UI.Xaml.Controls?

@timunie
Copy link
Contributor

timunie commented May 18, 2020

Hi @evilbaschdi

Can you provide a Demo App on github? That way we can have a look and maybe find a solution.

Thank you in advance

Happy coding
Tim

@evilbaschdi
Copy link
Author

@timunie
Copy link
Contributor

timunie commented May 29, 2020

Hi @evilbaschdi
I found a solution, at least a workaround.

// 1. We get the PathData as string which should be renderd
string pathData = new PackIconMaterial() { Kind = PackIconMaterialKind.CubeOutline }.Data;

// 2. We create the UWP Path which is needed to render
Geometry geometry = (Geometry)XamlBindingHelper.ConvertValue(typeof(Geometry), pathData);

// 3. Create the PathIcon and set the Foreground
System.Windows.Media.Color accentColor = (System.Windows.Media.Color)FindResource("MahApps.Colors.Accent");
PathIcon pathIcon = new PathIcon()
{
    Data = geometry,
    Foreground = new SolidColorBrush(Color.FromArgb(accentColor.A, accentColor.R, accentColor.G, accentColor.B))
};

// 4. Add it to your Panel
stackPanel.Children.Add(pathIcon);

The result:
image

I hope this helps. Happy coding
Tim

@punker76
Copy link
Member

punker76 commented May 7, 2024

I’m closing this issue because it has been inactive for a long time. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on for so long, then it seems no one has the time to implement this.

Please reopen if you still encounter this issue with the latest stable version and then please use the issue template.

Thank you! 🙏

@punker76 punker76 closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants