我ListView在窗户上。该ListView的默认ItemsPanel被替换WrapPanel。我也有DataTemplate它的ListViewItem秒。在运行系统中,主窗口将在一段时间内不响应,因为它ListView具有700个(并不断增加)ListViewItem(来自数据绑定)。有没有办法使主窗口保持响应?
可选:ListView未准备好时,我希望在ProgressBar上方显示一条文本(或可能的话),ListView并说“请稍候...”或“正在加载物品...”之类的内容。
XAML:
<ListView x:Name="MyListView" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" HorizontalAlignment="Left" Height="577" VerticalAlignment="Top" Width="902" ScrollViewer.HorizontalScrollBarVisibility="Auto" Foreground="Black" Margin="10,10,0,0" ScrollViewer.CanContentScroll="True" BorderBrush="#FFC54B4B" BorderThickness="3" Background="White">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel MaxWidth="{Binding (FrameworkElement.ActualWidth),
RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"
ItemWidth="{Binding (ListView.View).ItemWidth,
RelativeSource={RelativeSource AncestorType=ListView}}"
MinWidth="{Binding ItemWidth, RelativeSource={RelativeSource Self}}"
ItemHeight="{Binding (ListView.View).ItemHeight,
RelativeSource={RelativeSource AncestorType=ListView}}" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Run Code Online (Sandbox Code Playgroud)
编辑:
我尝试了这个:
List<something> MyList = new List<something>();
ThreadPool.QueueUserWorkItem(_ =>
{
( Create MyList here...)
Dispatcher.BeginInvoke(new Action(() => …Run Code Online (Sandbox Code Playgroud) 我有一些ListViewItem来自集合的 s,我创建了一个DataTemplate ,以便每个ListViewItem都有 aButton作为子控件:
<Window.Resources>
<DataTemplate x:Key="ItemTemplate_AwesomeTemplate">
<StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
<Button Content="Awesome Button" Click="Awesome_Button_Click" HorizontalContentAlignment="Center" VerticalAlignment="Bottom" FontWeight="Bold" Foreground="Black"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<ListView x:Name="AwesomeListView" HorizontalAlignment="Left" Height="577" VerticalAlignment="Top" Width="934" ScrollViewer.HorizontalScrollBarVisibility="Visible" Foreground="Black" Margin="10,10,0,0">
<ListView.View>
<GridView>
<GridViewColumn Header="AwesomeHeader" Width="250" CellTemplate="{StaticResource ItemTemplate_AwesomeTemplate}"/>
</GridView>
</ListView.View>
</ListView>
Run Code Online (Sandbox Code Playgroud)
当我单击某个时Button,有没有办法更改包含单击IsSelected的属性?ListViewItemButton
using (var streamWriter = new StreamWriter(SomeRequest.GetRequestStream()))
{
string json = JsonConvert.SerializeObject(new
{
Type_member1 = "StacOverFlow",
Type_member2 = sometext,
Type_member3 = 0,
private = true
});
streamWriter.Write(json);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,有一个名为"private"的Type成员.当然,当我键入它时,会弹出一条消息并告诉我:
"无效的表达术语'私人'"
将"private"置于引号内将返回此错误:
"无效的匿名类型成员声明者.bla bla bla ..."
有办法解决这个问题吗?
我想将一个预定义的字符串数组写入file.txt,如下所示:
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
char *somestr[] = {"haha\n", "aww\n", "hmm\n", "hello\n", "there\n"};
int filedesc = open("testfile.txt", O_WRONLY | O_APPEND | O_CREAT);
for (int i = 0; i < 5; ++i) {
write(filedesc, somestr[i], 24);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这将创造testfile.txt.预期的文件内容:
haha
aww
hmm
hello
there
Run Code Online (Sandbox Code Playgroud)
但是当我尝试时,它给出了一个奇怪的结果.实际内容:
haha\00aww\00hmm\00hello\00there\00aww\00hmm\00hello\00there\00testfihmm\00hello\00there\00testfile.txhello\00there\00testfile.txt\00\00there\00testfile.txt\00\00; 4\00\00\00