小编Tvd*_*Tvd的帖子

问题SSL证书C#

在我的C#应用​​程序中,我必须通过https调用Web服务并使用我已经拥有的.crt文件进行验证.以下是满足此类需求的正确解决方案.我得到一个有效的解决方案后,我已经更新了这篇文章,认为它可能会帮助像我这样的人.

解决方案: 以下代码只需在整个应用程序执行中执行一次.有了这个,我们设置ServerCertification和SSL属性,每当调用reqest时将使用它们:

        public static void setSSLCertificate()
    {
        clientCert = new X509Certificate2(AUTHEN_CERT_FILE); // Pointing to the .crt file that will be used for server certificate verification by the client
        System.Net.ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(customXertificateValidation);
    }

    public static bool customXertificateValidation(Object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPoicyErrors)
    {
        switch (sslPoicyErrors)
        {
            case System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors:
            case System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch:
            case System.Net.Security.SslPolicyErrors.RemoteCertificateNotAvailable:
                break;
        }

        return clientCert.Verify();  // Perform the Verification and sends the result
    }
Run Code Online (Sandbox Code Playgroud)

请求通常像我们没有实现SSL那样完成.这是一个Post请求代码:

        private static String SendPost(String uri, String post_data)
    {
        String resData = …
Run Code Online (Sandbox Code Playgroud)

c# exception ssl-certificate webexception

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

Android Service可以无需启动即可绑定?

在许多文章,教程,文档,到目前为止,我们调用startService()或bindService(),都启动了服务.我们也可以同时打电话,但这是一个不同的故事.没有startService()我无法bindService.

    private void bindTunManagerService(int flags) {
    TunnelManagerService.setParentActivity(this);
    Intent bindIntent = new Intent(this, TunnelManagerService.class);
    startService(bindIntent);
    tunManagerServiceStarted = bindService(bindIntent, tunConnection, BIND_AUTO_CREATE);

    Log.d(TAG, "tunManagerServiceStarted  : " + tunManagerServiceStarted + ", ** tunManagerService = " + tunManagerService );
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,如果我注释startService(),bindService返回false并且tunManagerService = null,即使onServiceConnected没有被激发,我得到"无法sart服务意图{...}未找到"消息.添加startService后,将调用服务的onCreate,onStart,onServiceConnected并成功绑定.

在实际使用中,首先是startServie是必要的,然后我们才能使用bindService().这意味着没有startSErvice,我们就无法bindService !! 如果这个语句错了,为什么我不能在没有启动的情况下bindService?

有任何想法吗 ????

代码已添加

ServiceConnection:

    private ServiceConnection tunConnection = new ServiceConnection() {

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        Log.d(TAG,"onServiceConnected" );
        tunManagerService = ITunnelManagerService.Stub.asInterface(service);
        doConnect();
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        Log.d(TAG,"onServiceDisconnected" );
        tunManagerService = null;
    }

};
Run Code Online (Sandbox Code Playgroud)

服务: …

android android-service

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

如何在DataTemplate中右对齐内容?

我有一个带有DataTemplate的List,它显示文本,旁边有一个"x"按钮.我希望"X"btn显示在最右边,所以它们都出现在同一个地方.我使用的XML是:

<ListBox Name="seiveListBox" ItemsSource="{Binding}" MinWidth="80" Height="120" ScrollViewer.VerticalScrollBarVisibility="Visible" >
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding}" />
                                            <Button Name="delSeiveFromListBtn" Content="X" ToolTip="Delete" Margin="8, 0, 0, 0" Click="delSeiveFromListBtn_Click"></Button>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
Run Code Online (Sandbox Code Playgroud)

我尝试在StackPanel中添加Grid inpalce,但没有成功.

如何设计它或将列表中的"x"对齐到每个项目的最右侧.

wpf list alignment datatemplate

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

WPF Combobox,字符串Bind为Int属性

我想要一个数字为1-8的Combobox,并将所选值绑定到int类型的属性"NumberOfZones".默认情况下,组合框返回字符串值,因此无法保存在int属性中.如何输入转换为int.

如何设置项目并在int中进行选择.

   <ComboBox Background="#FFB7B39D" Height="23" Name="cboNumZones" Width="74" Margin="158,16,368,247" Grid.Row="2" SelectionChanged="cboNumZones_SelectionChanged" 
    SelectedValue="{Binding Path=NumberOfZones, Mode=TwoWay}">
   </ComboBox>
                <!--
                <ComboBoxItem >1</ComboBoxItem>
                    <ComboBoxItem >2</ComboBoxItem>
                    <ComboBoxItem >3</ComboBoxItem>
                    <ComboBoxItem >4</ComboBoxItem>
                    <ComboBoxItem >5</ComboBoxItem>
                    <ComboBoxItem >6</ComboBoxItem>
                    <ComboBoxItem >7</ComboBoxItem>
                    <ComboBoxItem >8</ComboBoxItem>
                -->
Run Code Online (Sandbox Code Playgroud)

包含NumberOfZones属性的对象是UserControl的DataContext.

非常感谢.

c# string wpf int combobox

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

WPF绑定多个标准

在我的MVVM中,在视图中我有一个DataGrid,我想根据2个条件启用行元素.DataGrid在1 col中有一个复选框(绑定到IsRowChecked属性),另一个col中有一个header复选框.我想启用行元素,如果1)IsRowChecked为真AND 2)选中标题复选框.

这个多重标准设置是否可行?

XAML

<DataGrid ItemsSource="{Binding SiList, Mode=TwoWay}" Name="dgvSiSelection">
      <DataGrid.Columns>                  
          <DataGridCheckBoxColumn Binding="{Binding IsRowChecked, Mode=TwoWay}"/>  
          <DataGridTextColumn Header="" Binding="{Binding Header}" MinWidth="108" IsReadOnly="True"/>
          <DataGridTemplateColumn>
              <DataGridTemplateColumn.Header>
                    <Grid>
                        <Grid.ColumnDefinitions>
                              <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Number of Chemicals" Grid.Column="0"  />
                    </Grid>                                        
               </DataGridTemplateColumn.Header>
               <DataGridTemplateColumn.CellTemplate>
                     <DataTemplate>
                          <TextBlock Text="{Binding Path=NumberOfCases}" />
                     </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>
                     <DataGridTemplateColumn.CellEditingTemplate>
                          <DataTemplate>
                              <TextBox IsEnabled="{Binding Path=IsRowChecked}" Text="{Binding Path=NumberOfCases, Mode=TwoWay}" />
                         </DataTemplate>
                     </DataGridTemplateColumn.CellEditingTemplate>
                 </DataGridTemplateColumn>


                 <!-- Value1  chkValue11-->
                 <DataGridTemplateColumn>
                     <DataGridTemplateColumn.Header>
                          <Grid>
                              <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                              </Grid.ColumnDefinitions>
                              <TextBlock Grid.Column="1" Text="Value1" IsEnabled="{Binding ElementName=chkValue11, Path=IsChecked}" />
                              <CheckBox Name="chkValue11"  Grid.Column="0" Width="16" />
                          </Grid>
                     </DataGridTemplateColumn.Header> …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf binding mvvm

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

iOS:自定义TableViewCell - 初始化自定义单元格

在我的TableView中,我有一个NSMutableArray*currList的dataSource - 它包含对象Agent的对象.我创建了自定义的TableCell并正确设置了所有内容.我在显示数据时发现问题:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *simpleTableIdentifier = @"ChatListCell";

     // Custom TableViewCell
     ChartListCell *cell = (ChartListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

     if (cell == nil) {
           // I believe here I am going wrong
           cell = [[ChartListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
           NSLog(@"Cell = %@", cell);  // Shows null
     }
     /*
     With UITableViewCell, things are working perfectly fine
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
     if (cell == nil) {
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
     }
     */
     Agent *agent = (Agent …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

iOS UITableView隐藏标题空间

在视图控制器中,我只有一个UITableView.在IB中,我将Header&Footer高度设为1,并且还添加了以下代码,但是在第1个单元格之上,它们有很多标题空间.我想摆脱那个空间.甚至滚动条也从第一个单元格开始,而不是从顶部开始.

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
CGFloat height = 0.0001;
return height;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
CGFloat height = 0.0001;
return height;
}

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// Create Empty View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,
                                                        [self tableView:self.visitorlistsTv heightForHeaderInSection:section]) ];
return view;
}

-(UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
// Create Empty View
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width,
                                                        [self tableView:self.visitorlistsTv heightForFooterInSection:section]) ];
return view;

}
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,页脚部分被隐藏.但是也无法隐藏标题.

查看解决方案的其他链接我还在View中添加了TableView,为tableview添加了约束,但仍然是标题部分仍然是它们的.

我哪里错了?如何摆脱它?

objective-c uitableview ios

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

如何设置文本框的高度?

对于我的单行文本框,我设置为Border = None.在这样做时,高度变得非常小.我无法以编程方式设置文本框的高度.如果我设置任何边框,然后再次罚款,但我不想要任何边框.即使文本也不完全可见 - 因此字体大小已经大于文本框高度.

我尝试创建自定义文本框,并设置它的高度,但它没有任何效果.如何处理这种情况?任何帮助都非常感谢.

c# winforms

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

OxyPlot:ColumnSeries/BarSeries显示每列的值

在我的WPF应用程序中,我使用OxyPlot.我将我的数据绑定到PlotModel,一切运行良好.

我想在图表上显示每列的值.可能吗?

作为参考,这个BarSeries现场示例,我希望分别显示2009年,2010年和2011年苹果的实际价值.即2009Apples列的Value1值,2010Apples的Value2值等.

我查看了BarSeries的API(对于可互换使用的WPF ColumnSeries).Bar和其他图表的教程.但无法在任何地方找到这样的东西.

我该如何实现这一目标?

wpf stackedbarseries oxyplot

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

android:将Tab的单击颜色设置为TableRow的背景颜色

我有一个TabLayout.在那里我有一个动态添加行的tablelayout.选择/单击TableRow时,我想将其背景颜色设置为Tab的按下或单击颜色.

我不想设置任何静态颜色,但想使用默认主题颜色.如何获取Tablayout的颜色信息?

如何处理标签的左侧和右侧?这是我得到的并且在将tab_background.xml设置为所有选项卡的backgroundRsourse之后: 标签bg设置

在左侧,两个图像都没有任何设置,但左右角是平滑的.在右侧,两个图像都带有setings,看到所选标签的角落只是一个正方形,它们应该圆整或像没有任何设置的那些一样发光.看来我必须使用tab_selected_bar_right和tab_selected_bar_left.我已将它们复制到我的drawable中,但无法弄清楚如何使用它们.在@mudit提供的下面的xml中给出了什么设置.

请指导我.任何帮助都非常感谢.我很急.

谢谢

tabs android

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