小编img*_*gen的帖子

如何在标准WPF ListView中启用UI虚拟化

我正在使用.NET 4.5/VS2012,我有一个像这样的ListView

<ListView 
    VirtualizingPanel.IsContainerVirtualizable="True"
    VirtualizingPanel.IsVirtualizing="True"
    VirtualizingPanel.IsVirtualizingWhenGrouping="True"
    Grid.Row="1"
    Name="eventLogList"
    Margin="5,0,5,0"
    BorderBrush="Black"
    BorderThickness="2"
    ItemsSource="{Binding EventLogs}"
    SelectedItem="{Binding SelectedEventLog}"
    local:ListViewSorter.CustomListViewSorter="EventLogViewer.UI.EventLogItemComparer"
    SelectionMode="Single">

    <ListView.GroupStyle>
        <GroupStyle HidesIfEmpty="False">
            <GroupStyle.ContainerStyle>
                <Style TargetType="GroupItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="GroupItem">
                                <Expander IsExpanded="True">
                                    <Expander.Header>
                                        <TextBlock FontSize="20" TextWrapping="Wrap" Margin="0,10,0,5" >
                                        <Bold><TextBlock Text="{Binding Name}"/></Bold> - <TextBlock FontSize="20" Text="{Binding ItemCount}"/> logs
                                    </TextBlock>
                                    </Expander.Header>
                                    <ItemsPresenter/>
                                </Expander>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </GroupStyle.ContainerStyle>
        </GroupStyle>
    </ListView.GroupStyle>
    <ListView.View>
        <GridView>
            <GridViewColumn 
                Header="event id"
                Width="120"
                DisplayMemberBinding="{Binding EventID}" />
            <GridViewColumn 
                Header="level"
                Width="160"
                DisplayMemberBinding="{Binding Level}" />
            <GridViewColumn 
                Header="server" 
                Width="160"
                DisplayMemberBinding="{Binding Server}" />
            <GridViewColumn 
                Header="log name" …
Run Code Online (Sandbox Code Playgroud)

c# wpf

5
推荐指数
3
解决办法
2万
查看次数

如何提高WPF后台任务的性能?

我正在构建一个WPF应用程序,它将在后台做一些繁重的工作.问题是,当我在单元测试中运行任务时,通常需要大约6~7秒才能运行.但是当我在WPF应用程序中使用TPL运行它时,运行需要12到30秒.有没有办法加速这件事.我正在调用LogParser的COM api来完成真正的工作.

更新:我调用Log Parser API的代码如下所示

var thread = new Thread(() =>
            {
                var logQuery = new LogQueryClassClass();
                var inputFormat = new COMEventLogInputContextClassClass
                {
                    direction = "FW",
                    fullText = true,
                    resolveSIDs = false,
                    formatMessage = true,
                    formatMsg = true,
                    msgErrorMode = "MSG",
                    fullEventCode = false,
                    stringsSep = "|",
                    iCheckpoint = string.Empty,
                    binaryFormat = "HEX"
                };
                try
                {
                    Debug.AutoFlush = true;
                    var watch = Stopwatch.StartNew();
                    var recordset = logQuery.Execute(query, inputFormat);
                    watch.Stop();

                    watch = Stopwatch.StartNew();
                    while (!recordset.atEnd())
                    {
                        var record = recordset.getRecord(); …
Run Code Online (Sandbox Code Playgroud)

c# com wpf task-parallel-library

5
推荐指数
1
解决办法
1051
查看次数

Android Studio和ADT具有不同的TypedArray值

我有一个使用Android Studio和ADT构建的应用程序.ADT是让其他人能够建立和运行的.我自己使用Android Studio.但最近当其他人添加了自定义UI控件时,Android Studio的版本将在具有自定义控件的UI中崩溃.经过深入调试后,我发现在Android Studio中,自定义控件的TypedArray具有与ADT版本不同的值.这是怎么发生的?我做了无数谷歌搜索没有成功.有人可以帮忙吗?

具体来说,getDimension(int index, float defValue)就是抛出异常,它的代码如下:

public float getDimension(int index, float defValue) {
    index *= AssetManager.STYLE_NUM_ENTRIES;
    final int[] data = mData;
    final int type = data[index+AssetManager.STYLE_TYPE];
    if (type == TypedValue.TYPE_NULL) {
        return defValue;
    } else if (type == TypedValue.TYPE_DIMENSION) {
        return TypedValue.complexToDimension(
            data[index+AssetManager.STYLE_DATA], mResources.mMetrics);
    }

    throw new UnsupportedOperationException("Can't convert to dimension: type=0x"
            + Integer.toHexString(type));
}
Run Code Online (Sandbox Code Playgroud)

您可以看到索引的类型不是TYPE_DIMENSION.这里的问题是mData,TypedArray类的成员,在运行时具有与ADT编译的APK文件不同的值.这很奇怪.问题是Custom UI控件采用jar文件的形式,而不是源代码形式.我猜这是Android Studio用生成的DEX代码做的事情导致了这个问题.

更新:从Android Studio 0.5.8升级到Android Studio 0.5.9后,异常的位置稍有变化.现在getFloat就是抛出异常.以下是源代码getFloat

/**
 * Retrieve the …
Run Code Online (Sandbox Code Playgroud)

android adt android-studio

5
推荐指数
0
解决办法
330
查看次数

字段未在Android Dagger项目中注入

我在Android上玩Dagger.我创建了一个模型UserPreference,一个调用的模块PreferenceModule和另一个类UserPreferenceTest的测试PreferenceModule.我有3个以下的java文件

UserPreference.java

package com.sigicn.preference;

import javax.inject.Inject;

import com.sigicn.commonmodels.Application;

public class UserPreference {
    public String name, weiboAccount;

    @Inject
    public Application[] frequentlyUsedApps;
}
Run Code Online (Sandbox Code Playgroud)

然后是PreferenceModule.java

package com.sigicn.preference;

import javax.inject.Singleton;

import com.sigicn.commonmodels.Application;
import com.sigicn.utils.MiscUtils;

import dagger.Module;
import dagger.Provides;

@Module(library = true, complete = true)
public class PreferenceModule {

    @Provides @Singleton UserPreference provideUserPreference() {
        UserPreference userPreference = new UserPreference();
        userPreference.frequentlyUsedApps = provideApplications();
        return userPreference;
    }

    @Provides @Singleton Application[] provideApplications() {
        return new Application[]{
                new Application(
                        MiscUtils.generateUUID(), "Youtube"), …
Run Code Online (Sandbox Code Playgroud)

java android dagger

5
推荐指数
1
解决办法
2965
查看次数

.NET 5.0 对字符串比较中关于 `IEnumerable&lt;T&gt;.OrderBy` 行为的重大更改

我有以下代码

    public class Model
    {
        public int Id { get; set; }
        public string OrderNumber { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            var models = new List<Model>
            {
                new Model {Id = 4, OrderNumber = "BT-3964-1"},
                new Model {Id = 2, OrderNumber = "BT3924"},
                new Model {Id = 1, OrderNumber = "bt3810v2"},
                new Model {Id = 5, OrderNumber = "BILL-TEST100"},
                new Model {Id = 3, OrderNumber = "BT-4887-Test3-Create"}
            };

            var reorderedModels = models.OrderBy(x => …
Run Code Online (Sandbox Code Playgroud)

.net c# .net-5

5
推荐指数
1
解决办法
100
查看次数

如何使Class.forName返回数组类型?

是否有可能Class.forName返回数组类型?现在,当我使用Class.forName("byte[]")它时抛出NoClassFound异常.

或一般,如何让Type[].class来自Type.class

java reflection

4
推荐指数
1
解决办法
3964
查看次数

Avalonia - 如何像 OneNote 桌面 UI 一样垂直放置 Tab 控件的选项卡

我是阿瓦洛尼亚的新手。在 WPF 中,您可以轻松地垂直放置选项卡控件的选项卡,如下面的文章 https://www.wpf-tutorial.com/tabcontrol/tab-positions/所示

我怎样才能在 Avalonia 实现类似的目标?

avaloniaui avalonia

4
推荐指数
1
解决办法
2884
查看次数

UI线程问题与MVVMCross中的视图模型

我正在使用MVVMCross和我的跨平台Windows Phone和Android应用程序.在核心项目的主视图模型中,我正在使用TPL进行一些后台工作,我想确保在回调中,当我更改视图模型的属性时将触发UI更改,代码运行在UI线程,我该如何实现?

对于代码,这是它喜欢的方式

    private MvxGeoLocation _currentLocation;
    private Task<MvxGeoLocation> GetCurrentLocation()
    {
        return Task.Factory.StartNew(() =>
            {
                while (_currentLocation == null && !LocationRetrievalFailed)
                {
                }
                return _currentLocation;
            });
    }

    var location = await GetCurrentLocation();
    if (LocationRetrievalFailed)
    {
        if (location == null)
        {
            ReverseGeocodingRequestFailed = true;
            return;
        }
        // Show toast saying that we are using the last known location
    }
    Address = await GooglePlaceApiClient.ReverseGeocoding(location);
Run Code Online (Sandbox Code Playgroud)

mvvm mvvmcross

3
推荐指数
2
解决办法
5254
查看次数

如何使用Visual Studio/Xamarin Studio绑定Xamarin中的*.AAR文件

我想绑定Xamarin中的HoloEverywhere.HoloEverywhere二进制文件是.aar文件.似乎如果我将其标记为InputJar,Java库绑定项目中没有任何反应.那么有没有办法让它发挥作用?

c# java xamarin.android xamarin

3
推荐指数
1
解决办法
2856
查看次数

如何从Java中的java.lang类型的对象中获取等价原语类型?

现在有一个简单的方法吗?假设我有一个可能是Long,Float,Integer,Byte等的Object,我如何从这个对象中获得它的等价原始类(Class)?

一种方法可以这样写

Class<?> getEquivalentPrimitiveType(Object obj)
{
}
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
59
查看次数

如何在没有JNDI的情况下使用DataSource检索数据库连接?

我们想要自己的数据库连接配置而不是使用JNDI,但在此期间,我们还想使用DataSource而不是使用DriverManager,怎么做?

java jndi jdbc

2
推荐指数
1
解决办法
3657
查看次数

如何在 MAC OSX Finder 上显示隐藏的 .svn 文件夹

我已经在我的 MAC 上检查了一个 subversion 存储库。但是我看不到我在 Windows 上可以看到的 .svn 文件夹(选中了显示隐藏文件/文件夹选项)。我如何在 Finder 中做到这一点?我正在使用最新的版本应用程序进行颠覆

svn macos

2
推荐指数
1
解决办法
3078
查看次数