-1

windows.forms コントロールを xaml に追加するアイデア。

このコードを取得しました

    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
                <WindowsFormsHost Margin="272,10,396,42" Width="240">
                    <wf:TextBox x:Name="txtAutoProductCode" AutoCompleteMode="SuggestAppend" AutoCompleteSource="CustomSource" />
                </WindowsFormsHost>

しかし、私は例外を得ました。どうすればよいかわかりません。私はここで立ち往生しています。

詳細な例外を以下に示します。

System.Windows.Markup.XamlParseException was unhandled
  HResult=-2146233087
  Message='Initialization of 'Billing.MainWindow' threw an exception.' Line number '6' and line position '9'.
  Source=PresentationFramework
  LineNumber=6
  LinePosition=9
  StackTrace:
       at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
       at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
       at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
       at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
       at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
       at System.Windows.Application.DoStartup()
       at System.Windows.Application.<.ctor>b__1(Object unused)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
4

2 に答える 2

1

それを機能させる唯一の方法は、分離コードでオートコンプリート プロパティを設定することでした。そうしないと、同じエラーが表示されます。ただし、InitializeComponent() の後に行う必要があります。

public MainWindow()
{
    InitializeComponent();

    txtAutoProductCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
    txtAutoProductCode.AutoCompleteCustomSource.Add("item1");
    txtAutoProductCode.AutoCompleteCustomSource.Add("item2");
}

<Grid>
    <WindowsFormsHost Margin="272,10,396,42" Width="240">
        <wf:TextBox x:Name="txtAutoProductCode" AutoCompleteMode="SuggestAppend"/>
    </WindowsFormsHost>
</Grid>
于 2013-10-28T09:43:47.987 に答える