我正在创建一个简单的用户控件,将弹出窗口与文本视图相结合,没什么了不起的.当我首先在窗口中设置它以将其全部设置出来时,它完美地工作,但当我将其移动到用户控件中以实际完成它时,它将无法正常工作.
我将最小值和最大值传递给控件,然后它会自动创建一个从该范围中选择的数字列表.在用户控件中,数字列表没有正确绑定,谁知道原因.也许有人可以看看我的代码.
我已经阅读了很多关于此问题的其他问题,但我们并不知道发生了什么.我的输出窗口没有出现任何错误,所以没有线索.无论如何,这是代码 -
UserControl.xaml
<UserControl x:Class="UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Me"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<StackPanel>
<TextBox Name="myTextbox"
Height="30"
Margin="0"
FontSize="14"
IsReadOnly="True"
Padding="5,2"
Text="{Binding Value}" />
<Popup x:Name="myPopup"
PlacementTarget="{Binding ElementName=myTextbox}"
StaysOpen="True">
<Popup.Style>
<Style TargetType="{x:Type Popup}">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=myTextbox, Path=IsFocused}" Value="True">
<Setter Property="IsOpen" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
<StackPanel>
<ListView Name="myListView"
Height="100"
MaxHeight="300"
ItemsSource="{Binding List,
UpdateSourceTrigger=PropertyChanged}"
SelectionChanged="ListView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<Label Width="100"
Height="30"
Margin="0"
Content="{Binding}"
FontFamily="Segoe UI"
FontSize="14"
Padding="5,2" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Width="200" Height="30" />
</StackPanel>
</Popup>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
UserControl.xaml.vb
Imports …Run Code Online (Sandbox Code Playgroud)