使用 Xceed.Wpf.Toolkit 中的 MaskedTextBox 时出现 SetConnectionId 异常

Exception from SetConnectionId when using MaskedTextBox from Xceed.Wpf.Toolkit

我将为我的 wpf 项目使用 MaskedTextbox,这样我就可以拥有一个带有 Mask 的文本框。我对如何使用它完全陌生。说明是下载扩展的 wpf 工具包,将其引用到您的项目中,它将起作用。

所以当我构建项目时,没有显示任何错误。但是,当我尝试转到有屏蔽文本框的表单时,发现错误 'Set connectionId threw an exception'。希望有人知道解决方案。我尝试像我看到的某些 post 一样重建它,但仍然无济于事。我的 xaml 代码是:

 <Page x:Class="Kiosk_Lobby_System.Transaction.Deposit.CashDeposit"
  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:wpftool="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  mc:Ignorable="d" 
  d:DesignHeight="450" d:DesignWidth="790"
Title="CashDeposit" Loaded="Page_Loaded" >

<Grid>
    <Grid Margin="10,10,-10,-10">
        <Frame Name="frame1" HorizontalAlignment="Right" Width="329" Margin="0,0,0,-16">
            <Frame.Content>
                <Grid Margin="0 90 0 0" HorizontalAlignment="Right" Width="339" Height="508">
                    <WrapPanel ItemHeight="73" ItemWidth="83" Height="385" Width="255" HorizontalAlignment="Center" Name="wrapPanel1" VerticalAlignment="Center" Margin="0,9,-20,114">
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="1" FontSize="26" Height="65" Name="button_numeric_1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="75" Click="button_numeric_1_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="2" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_2" VerticalAlignment="Top" Width="75" Click="button_numeric_2_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="3" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_3" VerticalAlignment="Top" Width="75" Click="button_numeric_3_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="4" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_4" VerticalAlignment="Top" Width="75" Click="button_numeric_4_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="5" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_5" VerticalAlignment="Top" Width="75" Click="button_numeric_5_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="6" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_6" VerticalAlignment="Top" Width="75" Click="button_numeric_6_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="7" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_7" VerticalAlignment="Top" Width="75" Click="button_numeric_7_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="8" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_8" VerticalAlignment="Top" Width="75" Click="button_numeric_8_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="9" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_9" VerticalAlignment="Top" Width="75" Click="button_numeric_9_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="." FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_dot" VerticalAlignment="Top" Width="75" OpacityMask="{x:Null}" Click="button_numeric_dot_Click" FontFamily="Arial"></Button>
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="0" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_0" VerticalAlignment="Top" Width="75" OpacityMask="{x:Null}" Foreground="Black" Click="button_numeric_0_Click" FontFamily="Arial" />
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="Del" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_delete" VerticalAlignment="Top" Width="75" Click="button_numeric_delete_Click" FontFamily="Arial" />
                    </WrapPanel>
                    <WrapPanel Height="72" Width="255" HorizontalAlignment="Center" Name="wrapPanel2" VerticalAlignment="Center" Margin="0,298,-20,138">
                        <Button Style="{StaticResource ResourceKey=keybutton}" Content="Clear All" FontSize="26" Height="65" HorizontalAlignment="Left" Name="button_numeric_clear" VerticalAlignment="Top" Width="241" OpacityMask="{x:Null}" Click="button_numeric_clear_Click" FontFamily="Arial"></Button>
                    </WrapPanel>
                </Grid>
            </Frame.Content>
        </Frame>
        <Frame HorizontalAlignment="Left" Name="frame2" Width="454" Margin="43,-28,0,12">

            <Frame.Content>
                <GroupBox Name="groupBox1" Width="416" Height="405" Margin="0 85 0 0" IsEnabled="True" HorizontalAlignment="Right">
                    <Grid Margin="0 -40 0 0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="413" Height="367" >
                        <Label Style="{StaticResource label}" Content="Account Number:" 
                               FontSize="22" FontWeight="Bold"  Height="45" 
                               HorizontalAlignment="Stretch" HorizontalContentAlignment="Left"
                               Margin="56,70,6,0" Name="lblAcccountNumber" 
                               VerticalAlignment="Top" VerticalContentAlignment="Center" />
          <wpftool:MaskedTextBox FontSize="22" Height="47" HorizontalAlignment="Center"
                                    HorizontalContentAlignment="Right" IsEnabled="True" Margin="0,117,0,0"
                                    Name="txtAccountNo" PreviewTextInput="number" VerticalAlignment="Top" 
                                    VerticalContentAlignment="Center" Width="300" PreviewMouseLeftButtonDown="txtAccountNo_PreviewMouseLeftButtonDown" PreviewKeyDown="txtPreviewKeyDown" PreviewMouseLeftButtonUp="txtAccountNo_PreviewMouseLeftButtonUp"
                                    Mask="_ _ _- _ _ _ - _ _ _ _ _ - _"/>
          <!--<TextBox AcceptsReturn="True" FontSize="22" Height="47" HorizontalAlignment="Center"
                                 HorizontalContentAlignment="Right" IsEnabled="True" Margin="0,117,0,0"
                                 Name="txtAccountNo" PreviewTextInput="number" VerticalAlignment="Top" 
                                 VerticalContentAlignment="Center" Width="300" PreviewMouseLeftButtonDown="txtAccountNo_PreviewMouseLeftButtonDown" PreviewKeyDown="txtPreviewKeyDown" PreviewMouseLeftButtonUp="txtAccountNo_PreviewMouseLeftButtonUp" />-->
                        <Label Style="{StaticResource label}" Content="If PSBank prepaid, indicate the card number." 
                               FontSize="12" Height="32" 
                               HorizontalAlignment="Stretch" HorizontalContentAlignment="Left"
                               Margin="56,165,6,0" Name="lblAcccountNumberMessage" 
                               VerticalAlignment="Top" VerticalContentAlignment="Center" />

                        <Label Style="{StaticResource label}" Content="Amount:" FontSize="22" 
                               FontWeight="Bold"  Height="45" HorizontalAlignment="Stretch"
                               HorizontalContentAlignment="Left" Margin="56,200,5,0"
                               Name="lblAmount" VerticalAlignment="Top" 
                               VerticalContentAlignment="Center" />

                        <TextBox AcceptsReturn="True" FontSize="22" Height="47" HorizontalAlignment="Center"
                                 HorizontalContentAlignment="Right" IsEnabled="True" Margin="56,244,58,0"
                                 Name="txtAmount" PreviewTextInput="number" VerticalAlignment="Top" 
                                 VerticalContentAlignment="Center" Width="300" PreviewMouseLeftButtonDown="txtAmount_PreviewMouseLeftButtonDown"
                                 PreviewKeyDown="txtPreviewKeyDown" IsReadOnly="False" PreviewMouseLeftButtonUp="txtAmount_PreviewMouseLeftButtonUp" LostFocus="txtAmount_LostFocus" />

                        <Button  Content="OK" FontSize="22" Height="45" HorizontalAlignment="Right"
                                Margin="0,0,62,-20"  Name="btnCashDeposit_next" Style="{StaticResource button}"
                                 VerticalAlignment="Bottom" Width="130" Click="btnCashDeposit_next_Click" />
                        <Button Content="Back" FontSize="22" Height="45" HorizontalAlignment="Left"  Margin="58,0,0,-20"  
                                Name="btnCashDeposit_cancel" Style="{StaticResource button}" VerticalAlignment="Bottom" Width="130" Click="btnCashDeposit_cancel_Click" />
        </Grid>
                </GroupBox>
            </Frame.Content>
        </Frame>
        <Label Style="{StaticResource label2}" Content="Cash Deposit"  FontSize="32"
               FontWeight="Bold" Height="50" HorizontalAlignment="Center" 
               HorizontalContentAlignment="Center" Margin="-10,15,0,0" Name="labelTitle" 
               VerticalAlignment="Top" VerticalContentAlignment="Center" Width="800" />
    </Grid>
</Grid>
 </Page>

尝试以下步骤:

  1. Right-click Xceed.Wpf.Toolkit.dll -> 属性 -> 解锁

  1. 引用属性 -> 将 "Copy Local" 设置为 True

感谢大家提出的建议!通过将本地副本设置为 True 然后将 xmlns:customName="wpftool" 添加到 xaml 使其工作! :)