How to add xbf files to visual studio project

前端 未结 2 1164
梦如初夏
梦如初夏 2021-01-14 00:26

I have created a class library for Windows Universal Platform (Win 10 UWP).

The library houses some UserControls.

When I add the dll from this library to a W

相关标签:
2条回答
  • 2021-01-14 01:16

    In addition to Thomas's answer, you need to check the "Generate library layout" option in the Build configuration under the project's Properties page.

    The files we need to reference:

    • ClassLibrary1(Class Library name) Folder
      • ClassLibrary1.xr.xml
      • CustomPopupControl.xaml
    • ClassLibrary1.dll
    • ClassLibrary1.pri -> Package Resource Index file

    Copy these files to anywhere and the UWP project just need to add reference to the ClassLibrary1.dll file in the Visual Studio, all of them will be added automatically.

    It just throws a xaml parse exception when I try to use the UserControl on the "InitializeComponent()" method

    Perhaps the .pri file is missing when you add the reference.

    0 讨论(0)
  • 2021-01-14 01:23

    Try to define your constructor as public and not internal.

    Also, your second constructor is calling base but i'm not sure to understand why you have/need it if it does not need any parameters.

    Try this code:

    public sealed partial class CustomPopupControl : UserControl
    {
        public CustomPopupControl()
        {
            this.InitializeComponent();    
    
            Debug.WriteLine("CustomPopupControl");
        }
    
        private void OnPopupLoaded(object sender, RoutedEventArgs e)
        {
            this.Popup_Container.HorizontalOffset = (Window.Current.Bounds.Width - Grid_Child.ActualWidth) / 2;
            this.Popup_Container.VerticalOffset = (Window.Current.Bounds.Height - Grid_Child.ActualHeight) / 2;
        }
    
        internal void OpenPopup()
        {
            Debug.WriteLine("OpenPopup");
            Popup_Container.IsOpen = true;
    
            var currentFrame = Window.Current.Content as Frame;
            var currentPage = currentFrame.Content as Page;
            currentPage.IsHitTestVisible = false;
    
            Debug.WriteLine("OpenPopup Done");
        }
    
        private void OnLayoutUpdated(object sender, object e)
        {
            if (Grid_Child.ActualWidth == 0 && Grid_Child.ActualHeight == 0)
            {
                return;
            }
    
            double ActualHorizontalOffset = Popup_Container.HorizontalOffset;
            double ActualVerticalOffset = Popup_Container.VerticalOffset;
    
            double NewHorizontalOffset = (Window.Current.Bounds.Width - Grid_Child.ActualWidth) / 2;
            double NewVerticalOffset = (Window.Current.Bounds.Height - Grid_Child.ActualHeight) / 2;
    
            if (ActualHorizontalOffset != NewHorizontalOffset || ActualVerticalOffset != NewVerticalOffset)
            {
                Popup_Container.HorizontalOffset = NewHorizontalOffset;
                Popup_Container.VerticalOffset = NewVerticalOffset;
            }
        }
    }
    

    Thanks,

    0 讨论(0)
提交回复
热议问题