应用程序是WPF .netframework
我需要将属性作为itemsource绑定到列表框中的类,该类位于.dll中。有一个主要问题,因为如果我绑定一些其他没有模型在dll中的Collection。它有效,但我需要在库中使用它。
的xmlns:C =" CLR-名称空间:MessageLibrary;装配= MessageLibrary"
我不知道如何修复它,我几乎尝试了一切
我查看了MSDN,并且完全相同的例子没有任何效果。我非常感谢有人解决这个问题
这是MainViewModel中的ItemSourceCollection
public ObservableCollection<ViewModelUser> AllUsers { get; set; }
public ObservableCollection<ViewModelRoom> AllRooms { get; set; }
AllUsers = new ObservableCollection<ViewModelUser>();
AllRooms = new ObservableCollection<ViewModelUser>();
这是我的xaml类:
<Window x:Class="ChatsUPClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ChatsUPClient"
xmlns:vm="clr-namespace:ChatsUPClient.ViewModel"
xmlns:c="clr-namespace:MessageLibrary;assembly=MessageLibrary"
Title="ChatsUP" Height="600" Width="900">
<Window.DataContext>
<vm:MainViewModel />
</Window.DataContext>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="*"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<TextBlock x:Name="UserNameTextBlock" Grid.Column="1" Grid.Row="0" Text="{Binding Path=LRName, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"></TextBlock>
<TextBox x:Name="MessageTextBox" Grid.Column="1" Grid.Row="3" TextWrapping="NoWrap" Text="{Binding Path=Input, Mode=TwoWay}"/>
<TextBox x:Name="MessageTimeLine" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" TextWrapping="Wrap" Text="{Binding Path=Output}" Grid.ColumnSpan="2" IsReadOnly="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" FontFamily="Lucida Sans Typewriter"/>
<Button x:Name="SendBtn" Content="Odeslat" Grid.Column="3" Grid.Row="3" Command="{Binding Path=ProcessCommand}"/>
<Button x:Name="CreateRoomBtn" Content="Vytvořit místnost"/>
<TextBox x:Name="CreateRoomName" Grid.Row="1"></TextBox>
<Grid Grid.Row="2" RenderTransformOrigin="0.505,0.438">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ListBox Grid.Column="0" Grid.Row="2" ItemsSource="{Binding AllRooms}" >
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type c:ViewModelUser}">
<TextBlock Text="{Binding Path= NameOfconversation}"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox Grid.Column="0" Grid.Row="0" ItemsSource="{Binding AllUsers}">
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type c:ViewModelUser}">
<TextBlock Text="{Binding NickName}"> </TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
<Button x:Name="Entry" Grid.Row="3" Grid.Column="0" Content="Vstoupit"></Button>
<StackPanel Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" x:Name="LoginPanel">
<TextBlock HorizontalAlignment="Center">Enter Name and Password</TextBlock>
<TextBox x:Name="NameTextBox" Text="{Binding Path=LRName}"/>
<TextBox x:Name="PasswordTextBox" Text="{Binding Path=LRPassword}"/>
<Button Content="Přihlásit se/Registrovat" Command="{Binding Path=LogingCommand}" Click="OnSave" />
</StackPanel>
</Grid>
库中的
类看起来像这样:
public class ViewModelUser
{
public int UserId { get; set; }
public string NickName { get; set; }
public string Password { get; set; }
}