.g.cs
파일을 변경할 수 없습니다. 실제로는 파일에 올바르게 표시되어 있습니다. 또한, "사용자 정의 컨트롤"이라는 용어를 사용하는 것은 불행한 일입니다. 이는 사용자가하려고하는 것이 아닌 특정 것을 의미하기 때문입니다. 그러나 좋은 소식은 당신이하려고하는 것이 가능하다는 것입니다. UserControl
에서
파생은 :
public class FancyUserControl : UserControl
{
// Your added common functionality.
}
후 정상 메커니즘을 사용하여 프로젝트에 새로운 UserControl
를 추가, 이제 UserControl1
을 가정 해 봅시다.
<local:FancyUserControl x:Class="SilverlightApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SilverlightApplication1"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
</Grid>
</local:FancyUserControl>
응용 프로그램에 적응하고, 그들에 local
로 세 줄에 특별한주의를 지불하고 나서 다음과 같이 UserControl.xaml
파일을 편집 할 수 있습니다.
public partial class UserControl1 : FancyUserControl
{
public UserControl1()
{
InitializeComponent();
}
}
을 및 Visual Studio는 아직 매우 행복하지 않을 것이다 그러나 결국 프로젝트를 재건하고 모든 것이 잘 될 것입니다 : 그런 다음 다음과 같이 UserControl1.xaml.cs
파일을 편집 할 수 있습니다.
클래스 UserControl1
은 UserControl
대신 FancyUserControl
에서 파생되었으며 일반적인 기능을 추가 할 수 있습니다. 컨트롤을 더 추가하려면 처음에 각 새 컨트롤을 프로젝트에 추가 한 후 XAML 및 코드 숨김을 수동으로 편집해야합니다.
매우 완벽한 답변을 주셔서 감사합니다. (당신은 .gs 파일을 편집하지 않아도되지만, 질문에 답할 때까지 필자가 필요한 기능을 수행 할 수있는 유일한 방법입니다)! – badpanda
+1 잘 구성된 답. – AnthonyWJones