小编Sas*_*sha的帖子

取消订阅observableCollection中的事件

假设我有一个observableCollection类:

CustomClassName testClass = new CustomClassName();
ObservableCollection<CustomClassName> collection = new ObservableCollection<CustomClassName>();
testClass.SomeEvent += OnSomeEvent;
collection.add(testClass);
Run Code Online (Sandbox Code Playgroud)

当我从集合中删除项目时,我是否需要手动取消订阅事件(OnSomeEvent),还是应该将其留给GC?取消订阅的最佳方式是什么?

c#

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

5.7.0用户未使用mailkit和strato服务器在asp.net core1中进行身份验证

在asp.net core 1应用程序中,我正在尝试使用mailkit库(版本1.8.1)向strato服务器发送电子邮件.我的代码:

  var emailMessage = new MimeKit.MimeMessage();
  try
  {
      emailMessage.From.Add(new MimeKit.MailboxAddress("Support", "some@test.com"));
      emailMessage.To.Add(new MimeKit.MailboxAddress("", "test@test.com"));
      emailMessage.Subject = "Subject";
      var bodyBuilder = new MimeKit.BodyBuilder();
      bodyBuilder.HtmlBody = @"<b>Some body</b>";

      emailMessage.Body = bodyBuilder.ToMessageBody(); 

      using (var client = new MailKit.Net.Smtp.SmtpClient())
      {
          client.Timeout = 15000;
          // Accept all SSL certificates (in case the server supports STARTTLS)
          client.ServerCertificateValidationCallback = (s, c, h, e) => true;

          await client.ConnectAsync("smtp.strato.de", 587, MailKit.Security.SecureSocketOptions.Auto);
          // Note: since we don't have an OAuth2 token, disable
          // the XOAUTH2 authentication mechanism.
          client.AuthenticationMechanisms.Remove("XOAUTH2"); …
Run Code Online (Sandbox Code Playgroud)

c# email mailkit asp.net-core

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

将值绑定为 ConverterParameter

在我的资源字典中,我有以下样式:

 <Style TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}" x:Key="{x:Type propgrid:PropertyGridDataAccessorItem}">
            <Style.Triggers>
                <Trigger Property="DataAccessorType" Value="Category">
                    <Setter Property="IsExpanded" Value="{Binding DisplayName, Converter={local:ExpandedCategoryConverter}}"/>
                </Trigger>
            </Style.Triggers>
  </Style>
Run Code Online (Sandbox Code Playgroud)

我需要将 viewModel 中的值绑定到 ConverterParameter,例如 ConverterParameter = {Binding MyProperty},但我们无法绑定到 ConverterParameter。

我该如何解决这个问题?

提前谢谢

wpf xaml binding

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

标签 统计

c# ×2

asp.net-core ×1

binding ×1

email ×1

mailkit ×1

wpf ×1

xaml ×1