小编Sch*_*Box的帖子

PATCH使用Windows.Web.Http.HttpClient类进行异步请求

我需要PATCHWindows.Web.Http.HttpClient课堂上提出要求,而且没有关于如何做的官方文件.我怎样才能做到这一点?

c# patch http dotnet-httpclient

62
推荐指数
4
解决办法
4万
查看次数

使用服务器套接字监听AS3(AIR)客户端中的传入连接

我设法创建了一个C#Server,它使用发送文件到AS3(AIR)客户端sockets.在AS3方面,我正在使用该flash.net.Socket库来接收数据TCP.

这是它的工作原理:
- >我打开我的服务器,它监听客户端(我可以创建一个连接设备列表);
- >我打开我的客户端,它会自动接收数据;

接收数据的触发事件是在客户端上进行的,即我只是打开服务器,当客户端打开时,它获取数据,触发这些事件:

socket.addEventListener(Event.CONNECT, onConnect); -> to connect to the server  
socket.addEventListener(Event.SOCKET_DATA, onDataArrival); -> to receive the data  
Run Code Online (Sandbox Code Playgroud)

现在我想做一些不同的事情.我不想在客户端上触发它,我希望服务器这样做,即,我想打开我的客户端,并在服务器上放入客户端将获取数据.

那么为什么我要尝试让客户端成为客户端/服务器呢?好吧,因为我的服务器是一台机器,而我的客户端是连接服务器的XXX移动设备,这是我实现这一目标的方法.

所以,鉴于我刚才所说的,我设法创建了我的AS3客户端/服务器应用程序,使用该flash.net.ServerSocket库就像我想要的那样.

首先我把客户端听了:

serverSocket.bind(portNumber, "10.1.1.212");
serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnectServer);
serverSocket.listen();
Run Code Online (Sandbox Code Playgroud)

然后我使用了接收数据 flash.net.Socket Event.SOCKET_DATA

这就是它.像我想要的那样工作.
但是,它flash.net.ServerSocket与移动设备不兼容,但......

所以这是我的问题:我需要从C#服务器发送文件(需要监听客户端以便我可以创建连接设备列表)到AS3(AIR)客户端,但我必须定义哪个客户端正在获取数据服务器,客户端需要随时准备接收数据,因此,听,但有很多,这就是我认为它们作为客户端的原因.

我的问题是:有没有办法让客户端监听传入的连接并在事件发生时触发事件,而不使用AS3中的服务器套接字?

此外,如果您有不同的方法来实现我的目标,而不使用C#服务器< - > AS3客户端/服务器逻辑,请随时提出您的意见.

sockets air serversocket actionscript-3

6
推荐指数
1
解决办法
7445
查看次数

条件语句中的C#6.0 null运算符

从我null在C#6.0中使用新运算符收集的内容中,您可以执行以下操作:

string name = people.FirstOrDefault()?.FullName;
Run Code Online (Sandbox Code Playgroud)

这很棒,但我经常遇到的一个验证是这样的:

object name = null;
if(name != null) {
    DoSomething();
} else {
    DoSomethingElse();
}
Run Code Online (Sandbox Code Playgroud)

鉴于新null运营商的目的,我希望这样的事情应该是可能的:

if(name?) {
    DoSomething();
} else {
    DoSomethingElse();
}
Run Code Online (Sandbox Code Playgroud)

根据我的理解,这里的问题是,当?检查的值实际上是null,它返回null,并且您需要语句的bool条件if.由于您无法直接将a转换null为a bool,是否有更简单的方法可以在不if(name != null)使用nullC#6.0中的new 运算符的情况下进行检查?

c# null c#-6.0

6
推荐指数
1
解决办法
4265
查看次数

在滚动结束时使用LoadMoreItemsAsync创建ListView

我有一个ListView在我的Windows Phone 8.1应用程序中,我可以有1000个或更多的结果,所以我需要每次滚动到底时实现加载更多功能,或一些其他逻辑和自然方式触发添加更多项目列表.
我发现它ListView有一个支持ISupportIncrementalLoading,并发现了这个实现:https://marcominerva.wordpress.com/2013/05/22/implementing-the-isupportincrementalloading-interface-in-a-window-store-app/ 这是我找到的更好的解决方案,因为它没有指定类型,即它是通用的.

我对此解决方案的问题是,当ListView被加载时,LoadMoreItemsAsync所有时间都需要运行,直到获得所有结果,这意味着用户不会触发加载更多.我不确定LoadMoreItemsAsync触发器是什么,但有些事情是不对的,因为它假设当我打开页面并在现场加载所有项目时,没有我做任何事情或任何滚动.这是实施:
IncrementalLoadingCollection.cs

public interface IIncrementalSource<T> {
    Task<IEnumerable<T>> GetPagedItems(int pageIndex, int pageSize);
    void SetType(int type);
}

public class IncrementalLoadingCollection<T, I> : ObservableCollection<I>, ISupportIncrementalLoading where T : IIncrementalSource<I>, new() {
    private T source;
    private int itemsPerPage;
    private bool hasMoreItems;
    private int currentPage;

    public IncrementalLoadingCollection(int type, int itemsPerPage = 10) {
        this.source = new T();
        this.source.SetType(type);
        this.itemsPerPage = itemsPerPage;
        this.hasMoreItems = true;
    }

    public bool …
Run Code Online (Sandbox Code Playgroud)

c# xaml listview windows-store-apps windows-phone-8.1

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

Swagger 将下划线转换为驼峰式

因此,我在使用 Swagger(Core 1.5.7)的 XML 对象定义时遇到了问题。这是我的 XML 代码:

<result status="ok">
    <another>
        <cards/>
        <customer my_super_id="2349027834"/>
        <someothers>
            <someother name="who-is-this" />
        </someothers>
    </another>
</result>
Run Code Online (Sandbox Code Playgroud)

这是我的 yml 代码:

result:
   type: object
   description: Some random description
   properties:
     status:
       type: string
       xml:
         attribute: true
     another:
       type: object
       properties:
         customer:
           type: object
           properties:
             superId:
               type: string
               xml:
                 name: my_super_id
                 attribute: true
Run Code Online (Sandbox Code Playgroud)

status我可以毫无问题地得到,但这my_super_idnull因为 Swagger 正在使用 CamelCase 中的参数生成模型类,即,mySuperId而不是my_super_id. 在我生成的模型类中,我有这个: public ResultAnotherCustomer(@JsonProperty("mySuperId") final String mySuperId)

有什么办法可以解决这个问题吗?

swagger

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

在Windows Phone 8.1类库中创建SQLite数据库

我有一个Windows Phone 8.1类库,我想稍后添加它作为Windows Phone 8.1 App项目的参考.

该ClassLibrary应负责创建和管理自己的数据库.我尝试SQLiteConnection在我的ClassLibrary中创建一个新的,但它抛出以下错误:A first chance exception of type 'System.InvalidOperationException' occurred in SQLitePCL.DLL但是,如果我在我的MainApp中做同样的事情一切正常.

那么,是否可以在ClassLibrary中创建一个SQLite数据库,该数据库负责在没有MainApp支持的情况下创建和管理它.

c# database sqlite portable-class-library windows-phone-8.1

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

将ListView中的SelectedItems绑定到Windows Phone 8.1中的ViewModel

我有以下代码:

<ListView SelectionMode="Multiple" ItemsSource="{Binding MyList}" ItemTemplate="{StaticResource MyListTemplate}">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>
Run Code Online (Sandbox Code Playgroud)

使用以下DataTemplate:

<Page.Resources>
    <!-- Data Template for the ListView -->
    <DataTemplate x:Key="MyListTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="150" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Image Grid.Column="0" Source="{Binding Path=Icon}" />
            <StackPanel Grid.Column="1" Orientation="Vertical">
                    <TextBlock Text="{Binding Path=EntryDate}" TextAlignment="Left" />
                <TextBlock Text="{Binding Path=Url}" TextAlignment="Left" />
                <TextBlock Text="{Binding Path=Text}" TextAlignment="Left" />
            </StackPanel>
        </Grid>
    </DataTemplate>
</Page.Resources>
Run Code Online (Sandbox Code Playgroud)

在我的ViewModel中,我有以下内容:

private ObservableCollection<MyModel> myList;
public ObservableCollection<MyModel> MyList {
    get { return myList; }
    set { …
Run Code Online (Sandbox Code Playgroud)

c# xaml mvvm windows-phone-8.1

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

从带有视图和数据库的Windows 8.1/Windows Phone 8.1应用程序创建一个dll

我正在创建一个Windows Phone 8.1应用程序,它应该充当其他Windows Phone 8.1应用程序的库.在我的新应用程序中,我可以将库项目添加到解决方案中,因此它可以作为一种外部库运行,这就是我想要它做的事情.
但是,我想知道是否有某种方法可以将我的WP Library应用程序导出到,例如,我可以添加的.dll作为我的新应用程序的参考.还有其他方法我可以做到这一点吗?

值得一提的是,我的Library App将拥有视图甚至数据库,而不仅仅是处理来自主应用程序的数据的方法.

c# windows dll visual-studio windows-phone-8.1

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

Windows Universal/Store App中的类库本地化

我有一个Windows Store应用程序项目和类库项目的解决方案,我想添加本地化支持.
如何将所有资源文件添加到我的类库并在我的应用程序和类库中使用它们?

c# localization windows-store-apps windows-8.1 windows-phone-8.1

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

使用自定义参数取消订阅/删除事件处理程序

Event Handler我使用以下代码订阅/创建自定义:

myButton.Click += (sender, e) => MyButtonClick(sender, e, stuff1, stuff2);
Run Code Online (Sandbox Code Playgroud)


我想取消订阅/删除并尝试如下:

myButton.Click += MyButtonClick;
Run Code Online (Sandbox Code Playgroud)

但抛出以下错误:
No overload for 'MyButtonClick' matches delegate 'System.Windows.RoutedEventHandler'


像这样:

myButton.Click += MyButtonClick(sender, e, stuff1, stuff2);
Run Code Online (Sandbox Code Playgroud)

但抛出以下错误:
Cannot implicitly convert type 'void' to 'System.Windows.RoutedEventHandler'


我如何取消订阅/删除它Event Handler

c# wpf events event-handling visual-studio

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

ProgressBar 背景属性在 Windows 应用商店应用程序中不起作用

ProgressBar在我的应用程序中添加了一个,我希望它有一个透明的背景,所以我这样做了:

<ProgressBar IsIndeterminate="True" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    <ProgressBar.Background>
        <SolidColorBrush Color="Black" Opacity="0.5" />
    </ProgressBar.Background>
</ProgressBar>
Run Code Online (Sandbox Code Playgroud)

在预览窗口中,一切看起来都很好,但是,当我运行我的应用程序时,它Background根本不存在。我找到的解决方案是将 放在ProgressBarGrid 中并Background在 中设置属性Grid,但由于预览显示它是正确的,并且属性在那里,它不应该工作吗?
更新:

根据@Chris W.的建议,我尝试覆盖ProgressBar元素的默认样式,如下所示:

<ProgressBar IsIndeterminate="True" Background="#FF000000" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="50">
    <ProgressBar.Style>
        <Style TargetType="ProgressBar">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ProgressBar">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Indeterminate">
                                        <Storyboard RepeatBehavior="Forever">
                                            <DoubleAnimation Storyboard.TargetName="DeterminateRoot"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="0.5"
                                                 Duration="0" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ProgressBar.Style>
</ProgressBar>
Run Code Online (Sandbox Code Playgroud)

但仍然没有果汁。

xaml progress-bar windows-store-apps windows-8.1 windows-phone-8.1

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

检测ScrollViewer何时停止滚动

我有一个SurfaceListBox里面有一个ScrollViewer。我可以访问它,ScrollViewer并且我想检测滚动结束的时间。由于它是一个触摸应用程序,可以拖动它,因此,我现在正在检测到PreviewTouchUp要执行的操作,但是,如果像我在智能手机上那样快速滑动,因为的内容ScrollViewer仍在拖动/ scrolling,PreviewTouchUp不会反映滚动结束,而是在之前触发。

我曾尝试Manipulation事件和其他几个人同时在ScrollViewerSurfaceListBox。我也尝试过ScrollViewer.PanningDeceleration,说实话,我看不出有什么不同。到目前为止,基本上没有运气。

因此,即使在PreviewTouchUp中,我也如何检测滚动的结束ScrollViewer

c# wpf scroll scrollviewer pixelsense

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