简体   繁体   English

将用户控件绑定到不会触发的contentcontrol验证规则

[英]bind user control to contentcontrol validation rules not firing

I have many user controls and i have main window which contains a content control and list box when user select from list box i bound the selected user control to the content control the problem is when the user control bound for the first time the validation rules is appears but when user control bound for the second time the validation rules disappear what is the problem ? 我有很多用户控件,并且我有一个主窗口,其中包含一个内容控件和一个列表框,当用户从列表框中进行选择时,我将选定的用户控件绑定到内容控件上,问题是当用户控件首次绑定验证规则时出现但是当用户控件第二次绑定验证规则消失时,这是什么问题? here is the main window : 这是主窗口:

<Grid>
    <ListBox x:Name="FormsListBox" Margin="0,5,0,5" Grid.Row="1" Grid.Column="0"  Width="180" ItemsSource="{Binding Formlist}" SelectedItem="{Binding SelectedFormInfo}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Image Source="Resources/Capture.PNG" ></Image>
                    <TextBlock Text="{Binding Path=FormName}"></TextBlock>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <StackPanel Grid.Row="1"  Grid.Column="1" x:Name="MainStackPanel" >
        <ContentControl  Content="{Binding Path=SelectedFormInfo.MainForm}">

        </ContentControl>
    </StackPanel>
</Grid>

here is the sample of validation role in user control: 这是用户控件中验证角色的示例:

<StackPanel Width="315" Margin="20,0,10,0">
    <TextBox x:Name="TxtWeaponNumber" Width="315">
        <TextBox.Text>
            <Binding Path="SelectedWeapon.weaponNumber" Mode="TwoWay"
                UpdateSourceTrigger="PropertyChanged" ValidatesOnNotifyDataErrors="True"
                ValidatesOnDataErrors="True" NotifyOnValidationError="True"
                NotifyOnSourceUpdated="True" NotifyOnTargetUpdated="True">
                <Binding.ValidationRules>
                    <validationRules:RequiredRule ValidatesOnTargetUpdated="True" ValidationStep="RawProposedValue" />
                </Binding.ValidationRules>
            </Binding>
        </TextBox.Text>
    </TextBox>
</StackPanel>

Note: MainForm in SelectedFormInfo contains thee selected user control 注意: SelectedFormInfo中的MainForm包含您选择的用户控件

我在AdornerDecorator中设置了用户控件,并且验证没有消失

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM