여기에 분명해야 할 것이없는 것 같지만 여기서는 공백을 그립니다.WPF 창에서 Panel에 UserControl을 추가하는 방법
내가 로그 창으로 사용하는TextBox
보다 더 아무것도 포함하지 않는 아주 원시적 UserControl을 구축했습니다
:
<UserControl x:Class="My.LoggerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Name="LoggerView">
<Grid x:Name="LayoutRoot">
<TextBox x:Name="LogWindow" AcceptsReturn="True"/>
</Grid>
</UserControl>
내가 그 그것을 할 수있는 가장 좋은 방법은 기대하지 않는다, 그러나 그것은해야 프로토 타입에 충분히 적합 할 것입니다.
코드 숨김 마찬가지로 간단하다
는public partial class LoggerControl : UserControl, ILogger
{
public LoggerControl()
{
InitializeComponent();
}
private LogLevel level = LogLevel.Warning;
#region ILogger
public LogLevel Level
{
get { return level; }
set { level = value; }
}
public void OnError(string s)
{
if (level >= LogLevel.Error)
LogWindow.AppendText("ERROR:::" + s + "\n");
}
// ...
#endregion
}
내가 알아낼 수있는 것은 내 MainWindow.xaml
에이 컨트롤을 추가하는 방법입니다. 단순화하면 내 창은 다음과 같습니다.
<Window x:Class="My.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:My"
Title="Test" Height="350" Width="525">
<Grid>
<local:LoggerControl x:Name="LogView" />
</Grid>
</Window>
Visual Studio 2010의 Designer는 기본 창을로드 할 수 없습니다. 주어진 오류는 다음과 같습니다.
'LoggerControl'유형의 값을 'UIElementCollection'유형의 콜렉터 또는 사전에 추가 할 수 없습니다.
이 오류 메시지에는 주요 검색 엔진 (중복 검색)에서 관련이없는 하나의 히트 만 있으므로 유용한 도움을 찾지 못했습니다. Microsoft의 문서는 이것이 제대로 작동 함을 암시하는 것으로 보입니다.
어떻게 해결할 수 있을까요?
이상하게도 최소한의 테스트 응용 프로그램을 만들 때이 문제가 발생하지 않습니다. 무엇이 이것을 일으킬 수 있습니까? – IanGilham