我对wpf / mvvm比较新,所以这可能是基本的东西,但是我有一个完全独立显示的用户控件,但是当我尝试将它加载到不同用户控件的stackpanel中时,它赢了根本不显示。有没有人知道我在这里做错了什么?我已经尝试设置宽度/高度/最小/最小高度,但没有一个有所不同。
这是可重复使用的用户控件的xaml:
<UserControl x:Class="BankProductControlLibrary.Views.IdentificationData"
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:bpcl="clr-namespace:BankProductControlLibrary.UserControls"
mc:Ignorable="d"
d:DesignHeight="102" d:DesignWidth="535">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BankProductSilverlightControl;component/Resources/Style.xaml"/>
<ResourceDictionary>
<Style x:Key="textBlockStyle" TargetType="TextBlock">
<Setter Property="Height" Value="28"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Width" Value="409" />
</Style>
<Style x:Key="textBlockStyle2" TargetType="TextBlock">
<Setter Property="Height" Value="23"/>
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Margin" Value="0,0,0,0" />
</Style>
<Style x:Key="comboBoxStyle" TargetType="ComboBox">
<Setter Property="Height" Value="23"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Width" Value="180" />
<Setter Property="Margin" Value="0,0,0,0" />
</Style>
<Style x:Key="textBoxStyle" TargetType="TextBox">
<Setter Property="Height" Value="23"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Width" Value="132" />
</Style>
<Style x:Key="dateBoxStyle" TargetType="bpcl:DateBox">
<Setter Property="Height" Value="23"/>
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Width" Value="75" />
</Style>
<Style x:Key="dateFormatingExplanationStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="9"/>
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Height" Value="23" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Width" Value="75"/>
<Setter Property="Text" Value="(mm/dd/yyyy)" />
</Style>
<Style x:Key="placeOfIssuanceExplanationStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="9"/>
<Setter Property="FontStyle" Value="Normal" />
<Setter Property="Height" Value="23" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Width" Value="Auto"/>
</Style>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel MinHeight="102" MinWidth="535">
<TextBlock Style="{StaticResource textBlockStyle}">
Select the ID provided from the drop-down list. ID must be a photo ID.
</TextBlock>
<Grid Style="{StaticResource ScreenStyle}" x:Name="LayoutRoot" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110*" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="88*" />
<ColumnDefinition Width="142*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!--Column0-->
<TextBlock Style="{StaticResource textBlockStyle2}"
Grid.Row="0" Grid.Column="0"
Text="Type:"
/>
<TextBlock Style="{StaticResource textBlockStyle2}"
Grid.Row="1" Grid.Column="0"
Text="Date of Issuance:"
/>
<TextBlock Style="{StaticResource textBlockStyle2}"
Grid.Row="2" Grid.Column="0"
Text="Place of Issuance:" />
<!--Column1-->
<ComboBox Name="Ids" Style="{StaticResource comboBoxStyle}"
Grid.Row="0" Grid.Column="1"
DisplayMemberPath="Value"
SelectedValuePath="Key"
SelectedValue="{Binding SelectedTaxpayerId, Mode=TwoWay}"
/>
<StackPanel Orientation="Horizontal"
Grid.Row="1" Grid.Column="1">
<bpcl:DateBox x:Name="IssueDate" Style="{StaticResource dateBoxStyle}"/>
<TextBlock Style="{StaticResource dateFormatingExplanationStyle}" />
</StackPanel>
<StackPanel Orientation="Horizontal"
Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2">
<!--This should be bpcl:AlphaTextBox-->
<TextBox Name="PlaceOfIssuance" Style="{StaticResource textBoxStyle}"
MaxLength="2"
Width="40"/>
<TextBlock Style="{StaticResource placeOfIssuanceExplanationStyle}"
Text="Enter state abbreviation or country code"
/>
</StackPanel>
<!--Column2-->
<TextBlock Style="{StaticResource textBlockStyle2}"
Grid.Row="0" Grid.Column="2"
Text="ID Number:"
/>
<TextBlock Style="{StaticResource textBlockStyle2}"
Grid.Row="1" Grid.Column="2"
Text="Expiration Date:"/>
<!--Column3-->
<TextBox Name="IdentificationNumber" Style="{StaticResource textBoxStyle}"
Grid.Row="0" Grid.Column="3" />
<StackPanel Orientation="Horizontal"
Grid.Row="1" Grid.Column="3" >
<bpcl:DateBox x:Name="ExpirationDate" Style="{StaticResource dateBoxStyle}"/>
<TextBlock Style="{StaticResource dateFormatingExplanationStyle}" />
</StackPanel>
</Grid>
</StackPanel>
</UserControl>
这是我尝试使用它的地方:
<UserControl x:Class="BankProductControlLibrary.Views.JTH.TaxpayerIdentificationView"
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:ltsa="http://www.libtax.com/LibTax/BankApp"
xmlns:bpcl="clr-namespace:BankProductControlLibrary.UserControls"
xmlns:views="clr-namespace:BankProductControlLibrary.Views"
mc:Ignorable="d ltsa"
d:DesignHeight="102" d:DesignWidth="520">
<UserControl.Resources>
<Style x:Key="validationStyle" TargetType="TextBlock">
<Setter Property="Height" Value="23" />
<Setter Property="Width" Value="Auto"/>
<Setter Property="Foreground" Value="Red" />
</Style>
</UserControl.Resources>
<StackPanel>
<views:IdentificationData x:Name="TPIdentification" />
<TextBlock Name="ValidationErrorMessage" Style="{StaticResource validationStyle}" />
</StackPanel>
</UserControl>
答案 0 :(得分:1)
我认为您应该检查用户控件是否具有datacontext。 WPF有一个很好的工具帮助了我很多: http://wpftutorial.net/Inspector.html