答:
Here is another, a bit simpler, way to get the desired output - accessing the table only once.

```<code>-- sample of data from your question
with t1(EmployeeID, Date1, Onleave) as(
  select 'ABH12345', cast('2016-01-01' as date),  0 union all
  select 'ABH12345', cast('2016-01-02' as date),  0 union all
  select 'ABH12345', cast('2016-01-03' as date),  0 union all
  select 'ABH12345', cast('2016-01-04' as date),  0 union all
  select 'ABH12345', cast('2016-01-05' as date),  0 union all
  select 'ABH12345', cast('2016-01-06' as date),  0 union all
  select 'ABH12345', cast('2016-01-07' as date),  0 union all
  select 'ABH12345', cast('2016-01-08' as date),  0 union all
  select 'ABH12345', cast('2016-01-09' as date),  0 union all
  select 'ABH12345', cast('2016-01-10' as date),  1 union all
  select 'ABH12345', cast('2016-01-11' as date),  1 union all
  select 'ABH12345', cast('2016-01-12' as date),  1 union all
  select 'ABH12345', cast('2016-01-13' as date),  1 union all
  select 'ABH12345', cast('2016-01-14' as date),  0 union all
  select 'ABH12345', cast('2016-01-15' as date),  0 union all
  select 'ABH12345', cast('2016-01-16' as date),  0 union all
  select 'ABH12345', cast('2016-01-17' as date),  0
)
-- actual query
select max(w.employeeid) as employeeid
     , min(w.date1)      as datevalidfrom
     , max(w.date1)      as datevalidto
     , max(w.onleave)    as onleave
  from (
        select row_number() over(partition by employeeid order by date1) -
               row_number() over(partition by employeeid, onleave order by date1) as grp
             , employeeid
             , date1
             , onleave
          from t1 s
        ) w
group by w.grp
order by employeeid, datevalidfrom
</code>```

Result:

```<code>employeeid datevalidfrom datevalidto onleave
---------- ------------- ----------- -----------
ABH12345   2016-01-01    2016-01-09  0
ABH12345   2016-01-10    2016-01-13  1
ABH12345   2016-01-14    2016-01-17  0
</code>```

Title: Rank records based on 1 column's changing value

Body:
Q: How can I rank records based on 1 column's changing value?

I have the following data (https://pastebin.com/vdTb1JRT):

EmployeeID  Date        Onleave
ABH12345    2016-01-01  0
ABH12345    2016-01-02  0
ABH12345    2016-01-03  0
ABH12345    2016-01-04  0
ABH12345    2016-01-05  0
ABH12345    2016-01-06  0
ABH12345    2016-01-07  0
ABH12345    2016-01-08  0
ABH12345    2016-01-09  0
ABH12345    2016-01-10  1
ABH12345    2016-01-11  1
ABH12345    2016-01-12  1
ABH12345    2016-01-13  1
ABH12345    2016-01-14  0
ABH12345    2016-01-15  0
ABH12345    2016-01-16  0
ABH12345    2016-01-17  0

I would like to produce the following results:

 EmployeeID DateValidFrom    DateValidTo     OnLeave
 ABH12345   2016-01-01       2016-01-09      0
 ABH12345   2016-01-10       2016-01-13      1
 ABH12345   2016-01-14       2016-01-17      0

So I'm thinking if I can somehow create a ranked column (like shown below) that increments based on the value in the Onleave column - partitioned by the EmployeeID column.

EmployeeID  Date        Onleave    RankedCol
ABH12345    2016-01-01  0          1
ABH12345    2016-01-02  0          1
ABH12345    2016-01-03  0          1
ABH12345    2016-01-04  0          1
ABH12345    2016-01-05  0          1
ABH12345    2016-01-06  0          1
ABH12345    2016-01-07  0          1
ABH12345    2016-01-08  0          1
ABH12345    2016-01-09  0          1
ABH12345    2016-01-10  1          2
ABH12345    2016-01-11  1          2
ABH12345    2016-01-12  1          2
ABH12345    2016-01-13  1          2
ABH12345    2016-01-14  0          3
ABH12345    2016-01-15  0          3
ABH12345    2016-01-16  0          3
ABH12345    2016-01-17  0          3

Then I would be able to do the following:

SELECT
 [EmployeeID]    = [EmployeeID]
,[DateValidFrom] = MIN([Date])
,[DateValidTo]   = MAX([Date])
,[OnLeave]       = [OnLeave]
FROM table/view/cte/sub-query
GROUP BY
 [EmployeeID]
,[OnLeave]
,[RankedCol]

Other solutions are very welcome..

Below is the test data :

WITH CTE AS ( SELECT EmployeeID = 'ABH12345', [Date] = CAST(N'2016-01-01' AS Date), [Onleave] = 0
UNION SELECT 'ABH12345', CAST(N'2016-01-02' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-03' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-04' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-05' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-06' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-07' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-08' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-09' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-10' AS Date), 1
UNION SELECT 'ABH12345', CAST(N'2016-01-11' AS Date), 1
UNION SELECT 'ABH12345', CAST(N'2016-01-12' AS Date), 1
UNION SELECT 'ABH12345', CAST(N'2016-01-13' AS Date), 1
UNION SELECT 'ABH12345', CAST(N'2016-01-14' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-15' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-16' AS Date), 0
UNION SELECT 'ABH12345', CAST(N'2016-01-17' AS Date), 0
)

SELECT * FROM CTE

Body:
Here is another, a bit simpler, way to get the desired output - accessing the table only once.

-- sample of data from your question
with t1(EmployeeID, Date1, Onleave) as(
  select 'ABH12345', cast('2016-01-01' as date),  0 union all
  select 'ABH12345', cast('2016-01-02' as date),  0 union all
  select 'ABH12345', cast('2016-01-03' as date),  0 union all
  select 'ABH12345', cast('2016-01-04' as date),  0 union all
  select 'ABH12345', cast('2016-01-05' as date),  0 union all
  select 'ABH12345', cast('2016-01-06' as date),  0 union all
  select 'ABH12345', cast('2016-01-07' as date),  0 union all
  select 'ABH12345', cast('2016-01-08' as date),  0 union all
  select 'ABH12345', cast('2016-01-09' as date),  0 union all
  select 'ABH12345', cast('2016-01-10' as date),  1 union all
  select 'ABH12345', cast('2016-01-11' as date),  1 union all
  select 'ABH12345', cast('2016-01-12' as date),  1 union all
  select 'ABH12345', cast('2016-01-13' as date),  1 union all
  select 'ABH12345', cast('2016-01-14' as date),  0 union all
  select 'ABH12345', cast('2016-01-15' as date),  0 union all
  select 'ABH12345', cast('2016-01-16' as date),  0 union all
  select 'ABH12345', cast('2016-01-17' as date),  0
)
-- actual query
select max(w.employeeid) as employeeid
     , min(w.date1)      as datevalidfrom
     , max(w.date1)      as datevalidto
     , max(w.onleave)    as onleave
  from (
        select row_number() over(partition by employeeid order by date1) -
               row_number() over(partition by employeeid, onleave order by date1) as grp
             , employeeid
             , date1
             , onleave
          from t1 s
        ) w
group by w.grp
order by employeeid, datevalidfrom

Result:

employeeid datevalidfrom datevalidto onleave
---------- ------------- ----------- -----------
ABH12345   2016-01-01    2016-01-09  0
ABH12345   2016-01-10    2016-01-13  1
ABH12345   2016-01-14    2016-01-17  0


来源: stackexchange

问:
DependencyProperty fails to create proper UpdateSourceTrigger inside binding when the binding has not set UpdateSourceTrigger explicitly
@update - See update below, please

I've got the UserControl that is used inside DataGridTemplateColumn. When I specify the binding like this {Binding MyProperty, UpdateSourceTrigger=PropertyChanged} it updates the source. However then I ommit UpdateSourceTrigger it doesn't update the source.

The DependencyProperty is created like this:

```<code>public static readonly DependencyProperty RatingValueProperty = DependencyProperty.Register(
    "RatingValue", typeof(int?), typeof(RatingControl), new FrameworkPropertyMetadata(default(int),
        FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
        DependencyPropertyChangedCallback,
        CoerceRatingValueCallback,
        false,
        UpdateSourceTrigger.PropertyChanged
));
</code>```

As you can see below, the Binding is created with Default flag when the UpdateSourceTrigger is omitted, and with PropertyChanged flag if not.

The "not working" binding (see line 26 on both examples):

```<code>0   _binding    {System.Windows.Data.Binding}   System.Windows.Data.BindingBase {System.Windows.Data.Binding}
1   AsyncState  null    object
2   BindingGroupName    ""  string
3   BindsDirectlyToSource   false   bool
4   Converter   null    System.Windows.Data.IValueConverter
5   ConverterCulture    null    System.Globalization.CultureInfo
6   ConverterCultureInternal    null    System.Globalization.CultureInfo
7   ConverterParameter  null    object
8   Delay   0   int
9   ElementName null    string
10  FallbackValue   {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
11  Flags   Default System.Windows.Data.BindingBase.BindingFlags
12  IsAsync false   bool
13  Mode    Default System.Windows.Data.BindingMode
14  NotifyOnSourceUpdated   false   bool
15  NotifyOnTargetUpdated   false   bool
16  NotifyOnValidationError false   bool
17  Path    {System.Windows.PropertyPath}   System.Windows.PropertyPath
18  RelativeSource  null    System.Windows.Data.RelativeSource
19  Source  null    object
20  SourceReference null    MS.Internal.Data.ObjectRef
21  StringFormat    null    string
22  TargetNullValue {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
23  TransfersDefaultValue   true    bool
24  TreeContextIsRequired   false   bool
25  UpdateSourceExceptionFilter null    System.Windows.Data.UpdateSourceExceptionFilterCallback
26  UpdateSourceTrigger Default System.Windows.Data.UpdateSourceTrigger
27  ValidatesOnDataErrors   false   bool
28  ValidatesOnExceptions   false   bool
29  ValidatesOnNotifyDataErrors true    bool
30  ValidatesOnNotifyDataErrorsInternal true    bool
31  ValidationRules Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
32  ValidationRulesInternal Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
33  XPath   null    string
34  _attachedPropertiesInPath   0   int
35  _bindsDirectlyToSource  false   bool
36  _doesNotTransferDefaultValue    false   bool
37  _flags  Default System.Windows.Data.BindingBase.BindingFlags
38  _isAsync    false   bool
39  _isSealed   true    bool
40  _ppath  {System.Windows.PropertyPath}   System.Windows.PropertyPath
41  _source {MS.Internal.Data.ExplicitObjectRef}    MS.Internal.Data.ObjectRef {MS.Internal.Data.ExplicitObjectRef}
42  _sourceInUse    None    System.Windows.Data.Binding.SourceProperties
43  _values {MS.Internal.UncommonValueTable}    MS.Internal.UncommonValueTable
44  Static members
</code>```

The "working" binding:

```<code>0   _binding    {System.Windows.Data.Binding}   System.Windows.Data.BindingBase {System.Windows.Data.Binding}
1   AsyncState  null    object
2   BindingGroupName    ""  string
3   BindsDirectlyToSource   false   bool
4   Converter   null    System.Windows.Data.IValueConverter
5   ConverterCulture    null    System.Globalization.CultureInfo
6   ConverterCultureInternal    null    System.Globalization.CultureInfo
7   ConverterParameter  null    object
8   Delay   0   int
9   ElementName null    string
10  FallbackValue   {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
11  Flags   PropDefault | ValidatesOnNotifyDataErrors   System.Windows.Data.BindingBase.BindingFlags
12  IsAsync false   bool
13  Mode    Default System.Windows.Data.BindingMode
14  NotifyOnSourceUpdated   false   bool
15  NotifyOnTargetUpdated   false   bool
16  NotifyOnValidationError false   bool
17  Path    {System.Windows.PropertyPath}   System.Windows.PropertyPath
18  RelativeSource  null    System.Windows.Data.RelativeSource
19  Source  null    object
20  SourceReference null    MS.Internal.Data.ObjectRef
21  StringFormat    null    string
22  TargetNullValue {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
23  TransfersDefaultValue   true    bool
24  TreeContextIsRequired   false   bool
25  UpdateSourceExceptionFilter null    System.Windows.Data.UpdateSourceExceptionFilterCallback
26  UpdateSourceTrigger PropertyChanged System.Windows.Data.UpdateSourceTrigger
27  ValidatesOnDataErrors   false   bool
28  ValidatesOnExceptions   false   bool
29  ValidatesOnNotifyDataErrors true    bool
30  ValidatesOnNotifyDataErrorsInternal true    bool
31  ValidationRules Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
32  ValidationRulesInternal Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
33  XPath   null    string
34  _attachedPropertiesInPath   0   int
35  _bindsDirectlyToSource  false   bool
36  _doesNotTransferDefaultValue    false   bool
37  _flags  PropDefault | ValidatesOnNotifyDataErrors   System.Windows.Data.BindingBase.BindingFlags
38  _isAsync    false   bool
39  _isSealed   true    bool
40  _ppath  {System.Windows.PropertyPath}   System.Windows.PropertyPath
41  _source {MS.Internal.Data.ExplicitObjectRef}    MS.Internal.Data.ObjectRef {MS.Internal.Data.ExplicitObjectRef}
42  _sourceInUse    None    System.Windows.Data.Binding.SourceProperties
43  _values {MS.Internal.UncommonValueTable}    MS.Internal.UncommonValueTable
44  Static members
</code>```

How to solve this so I don't have to set "UpdateSourceTrigger=PropertyChanged" explicitly in WPF.

@update 2017-06-03

I have attached link (click) to the example project to illustrate the issue. Please open MainWindow.xaml and fiddle with lines #35-#39. The line #36 presents the not-working behaviour, the line #39 presents the working behaviour.

Line #36

```<code><local:RatingControl StarsCount="5" RatingValue="{Binding Rating, PresentationTraceSources.TraceLevel=High}" IsReadonly="False" HorizontalContentAlignment="Center" />
</code>```

Line #39

```<code><local:RatingControl StarsCount="5" RatingValue="{Binding Rating, UpdateSourceTrigger=PropertyChanged, PresentationTraceSources.TraceLevel=High}" IsReadonly="False" HorizontalContentAlignment="Center" />
</code>```

@Edit - Requested XAML code

```<code><UserControl x:Class="so_44248130.RatingControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="24" d:DesignWidth="240">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <BitmapImage x:Key="StarEmpty" UriSource="pack://application:,,,/so_44248130;component/star_black_empty.png" CacheOption="OnLoad" CreateOptions="IgnoreImageCache" />
        <BitmapImage x:Key="StarFull" UriSource="pack://application:,,,/so_44248130;component/star_black_full.png" />
    </UserControl.Resources>
    <Grid>
        <ItemsControl ItemsSource="{Binding StarsList, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Button Grid.Row="0" Grid.Column="0" Width="24" Height="24" MaxHeight="24" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Tag="{Binding}" Padding="0" HorizontalContentAlignment="Center" Click="ButtonBase_OnClick">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="24" />
                                </Grid.ColumnDefinitions>

                                <Rectangle Grid.Row="0" Grid.Column="0" Width="{Binding EmptyStarWidth}" Height="24" HorizontalAlignment="Left">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="{StaticResource StarEmpty}"
                                        TileMode="Tile"
                                        Stretch="Uniform"
                                        AlignmentY="Top"
                                        Viewport="0,0,24,3000"
                                        ViewportUnits="Absolute" />
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Rectangle Grid.Row="0" Grid.Column="0" Width="{Binding FullStarWidth}" Height="24" HorizontalAlignment="Left">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="{StaticResource StarFull}"
                                        TileMode="Tile"
                                        Stretch="Uniform"
                                        AlignmentY="Top"
                                        Viewport="0,0,24,3000"
                                        ViewportUnits="Absolute" />
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Grid>
                        </Button>
                        <Rectangle Grid.Row="0" Grid.Column="0" Height="24" Width="24" Visibility="{Binding IsReadonly, Converter={StaticResource BooleanToVisibilityConverter}}" Fill="#02FFFFFF" />
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>
</code>```

答:
Is there any specific reason for using FrameworkPropertyMetadata?

if you are just backing up a property then try using PropertyMetadata.

Refer here for more details.

ContentLicense: CC BY-SA 3.0

Body:
@update - See update below, please

I've got the UserControl that is used inside DataGridTemplateColumn. When I specify the binding like this {Binding MyProperty, UpdateSourceTrigger=PropertyChanged} it updates the source. However then I ommit UpdateSourceTrigger it doesn't update the source.

The DependencyProperty is created like this:

public static readonly DependencyProperty RatingValueProperty = DependencyProperty.Register(
    "RatingValue", typeof(int?), typeof(RatingControl), new FrameworkPropertyMetadata(default(int),
        FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
        DependencyPropertyChangedCallback,
        CoerceRatingValueCallback,
        false,
        UpdateSourceTrigger.PropertyChanged
));

As you can see below, the Binding is created with Default flag when the UpdateSourceTrigger is omitted, and with PropertyChanged flag if not.

The "not working" binding (see line 26 on both examples):

0   _binding    {System.Windows.Data.Binding}   System.Windows.Data.BindingBase {System.Windows.Data.Binding}
1   AsyncState  null    object
2   BindingGroupName    ""  string
3   BindsDirectlyToSource   false   bool
4   Converter   null    System.Windows.Data.IValueConverter
5   ConverterCulture    null    System.Globalization.CultureInfo
6   ConverterCultureInternal    null    System.Globalization.CultureInfo
7   ConverterParameter  null    object
8   Delay   0   int
9   ElementName null    string
10  FallbackValue   {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
11  Flags   Default System.Windows.Data.BindingBase.BindingFlags
12  IsAsync false   bool
13  Mode    Default System.Windows.Data.BindingMode
14  NotifyOnSourceUpdated   false   bool
15  NotifyOnTargetUpdated   false   bool
16  NotifyOnValidationError false   bool
17  Path    {System.Windows.PropertyPath}   System.Windows.PropertyPath
18  RelativeSource  null    System.Windows.Data.RelativeSource
19  Source  null    object
20  SourceReference null    MS.Internal.Data.ObjectRef
21  StringFormat    null    string
22  TargetNullValue {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
23  TransfersDefaultValue   true    bool
24  TreeContextIsRequired   false   bool
25  UpdateSourceExceptionFilter null    System.Windows.Data.UpdateSourceExceptionFilterCallback
26  UpdateSourceTrigger Default System.Windows.Data.UpdateSourceTrigger
27  ValidatesOnDataErrors   false   bool
28  ValidatesOnExceptions   false   bool
29  ValidatesOnNotifyDataErrors true    bool
30  ValidatesOnNotifyDataErrorsInternal true    bool
31  ValidationRules Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
32  ValidationRulesInternal Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
33  XPath   null    string
34  _attachedPropertiesInPath   0   int
35  _bindsDirectlyToSource  false   bool
36  _doesNotTransferDefaultValue    false   bool
37  _flags  Default System.Windows.Data.BindingBase.BindingFlags
38  _isAsync    false   bool
39  _isSealed   true    bool
40  _ppath  {System.Windows.PropertyPath}   System.Windows.PropertyPath
41  _source {MS.Internal.Data.ExplicitObjectRef}    MS.Internal.Data.ObjectRef {MS.Internal.Data.ExplicitObjectRef}
42  _sourceInUse    None    System.Windows.Data.Binding.SourceProperties
43  _values {MS.Internal.UncommonValueTable}    MS.Internal.UncommonValueTable
44  Static members

The "working" binding:

0   _binding    {System.Windows.Data.Binding}   System.Windows.Data.BindingBase {System.Windows.Data.Binding}
1   AsyncState  null    object
2   BindingGroupName    ""  string
3   BindsDirectlyToSource   false   bool
4   Converter   null    System.Windows.Data.IValueConverter
5   ConverterCulture    null    System.Globalization.CultureInfo
6   ConverterCultureInternal    null    System.Globalization.CultureInfo
7   ConverterParameter  null    object
8   Delay   0   int
9   ElementName null    string
10  FallbackValue   {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
11  Flags   PropDefault | ValidatesOnNotifyDataErrors   System.Windows.Data.BindingBase.BindingFlags
12  IsAsync false   bool
13  Mode    Default System.Windows.Data.BindingMode
14  NotifyOnSourceUpdated   false   bool
15  NotifyOnTargetUpdated   false   bool
16  NotifyOnValidationError false   bool
17  Path    {System.Windows.PropertyPath}   System.Windows.PropertyPath
18  RelativeSource  null    System.Windows.Data.RelativeSource
19  Source  null    object
20  SourceReference null    MS.Internal.Data.ObjectRef
21  StringFormat    null    string
22  TargetNullValue {{DependencyProperty.UnsetValue}}   object {MS.Internal.NamedObject}
23  TransfersDefaultValue   true    bool
24  TreeContextIsRequired   false   bool
25  UpdateSourceExceptionFilter null    System.Windows.Data.UpdateSourceExceptionFilterCallback
26  UpdateSourceTrigger PropertyChanged System.Windows.Data.UpdateSourceTrigger
27  ValidatesOnDataErrors   false   bool
28  ValidatesOnExceptions   false   bool
29  ValidatesOnNotifyDataErrors true    bool
30  ValidatesOnNotifyDataErrorsInternal true    bool
31  ValidationRules Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
32  ValidationRulesInternal Count = 0   System.Collections.ObjectModel.Collection<System.Windows.Controls.ValidationRule> {MS.Internal.Controls.ValidationRuleCollection}
33  XPath   null    string
34  _attachedPropertiesInPath   0   int
35  _bindsDirectlyToSource  false   bool
36  _doesNotTransferDefaultValue    false   bool
37  _flags  PropDefault | ValidatesOnNotifyDataErrors   System.Windows.Data.BindingBase.BindingFlags
38  _isAsync    false   bool
39  _isSealed   true    bool
40  _ppath  {System.Windows.PropertyPath}   System.Windows.PropertyPath
41  _source {MS.Internal.Data.ExplicitObjectRef}    MS.Internal.Data.ObjectRef {MS.Internal.Data.ExplicitObjectRef}
42  _sourceInUse    None    System.Windows.Data.Binding.SourceProperties
43  _values {MS.Internal.UncommonValueTable}    MS.Internal.UncommonValueTable
44  Static members

How to solve this so I don't have to set "UpdateSourceTrigger=PropertyChanged" explicitly in WPF.

@update 2017-06-03

I have attached link (click) to the example project to illustrate the issue. Please open MainWindow.xaml and fiddle with lines #35-#39. The line #36 presents the not-working behaviour, the line #39 presents the working behaviour.

Line #36

<local:RatingControl StarsCount="5" RatingValue="{Binding Rating, PresentationTraceSources.TraceLevel=High}" IsReadonly="False" HorizontalContentAlignment="Center" />

Line #39

<local:RatingControl StarsCount="5" RatingValue="{Binding Rating, UpdateSourceTrigger=PropertyChanged, PresentationTraceSources.TraceLevel=High}" IsReadonly="False" HorizontalContentAlignment="Center" />

@Edit - Requested XAML code

<UserControl x:Class="so_44248130.RatingControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="24" d:DesignWidth="240">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <BitmapImage x:Key="StarEmpty" UriSource="pack://application:,,,/so_44248130;component/star_black_empty.png" CacheOption="OnLoad" CreateOptions="IgnoreImageCache" />
        <BitmapImage x:Key="StarFull" UriSource="pack://application:,,,/so_44248130;component/star_black_full.png" />
    </UserControl.Resources>
    <Grid>
        <ItemsControl ItemsSource="{Binding StarsList, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Button Grid.Row="0" Grid.Column="0" Width="24" Height="24" MaxHeight="24" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Tag="{Binding}" Padding="0" HorizontalContentAlignment="Center" Click="ButtonBase_OnClick">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="24" />
                                </Grid.ColumnDefinitions>

                                <Rectangle Grid.Row="0" Grid.Column="0" Width="{Binding EmptyStarWidth}" Height="24" HorizontalAlignment="Left">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="{StaticResource StarEmpty}"
                                        TileMode="Tile"
                                        Stretch="Uniform"
                                        AlignmentY="Top"
                                        Viewport="0,0,24,3000"
                                        ViewportUnits="Absolute" />
                                    </Rectangle.Fill>
                                </Rectangle>
                                <Rectangle Grid.Row="0" Grid.Column="0" Width="{Binding FullStarWidth}" Height="24" HorizontalAlignment="Left">
                                    <Rectangle.Fill>
                                        <ImageBrush ImageSource="{StaticResource StarFull}"
                                        TileMode="Tile"
                                        Stretch="Uniform"
                                        AlignmentY="Top"
                                        Viewport="0,0,24,3000"
                                        ViewportUnits="Absolute" />
                                    </Rectangle.Fill>
                                </Rectangle>
                            </Grid>
                        </Button>
                        <Rectangle Grid.Row="0" Grid.Column="0" Height="24" Width="24" Visibility="{Binding IsReadonly, Converter={StaticResource BooleanToVisibilityConverter}}" Fill="#02FFFFFF" />
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>


问:
Calculate HTTPS POST Request size
I have a middlet that sends data to a servlet.

Anyone knows how can I calculate the size of request of the middlet in a servlet?

I'm tring to sum of request header + request size + certificate size
Is it correct?

With this I'm trying to recreate the request:

http://wikis.sun.com/display/WebServerdocs/Analyzing+SSL+Requests+and+Responses

答:
Read more about SSL handshake:

I think the conversation round-trip may worry you as well as packet sizes.

Once handshake phase is finished and connection is reused (keepalive) only HTTP data is sent, encrypted of course.

Title: Calculate HTTPS POST Request size

ContentLicense: CC BY-SA 2.5


问:
How to use Data Binding and Kotlin in Android Studio 3.0.0
I just started to use Android Studio 3.0.0, but every time I try to build my project I get this error:

```<code>Error:Circular dependency between the following tasks:
:app:compileDebugKotlin
+--- :app:dataBindingExportBuildInfoDebug
|    \--- :app:compileDebugKotlin (*)
\--- :app:kaptDebugKotlin
     \--- :app:dataBindingExportBuildInfoDebug (*)
(*) - details omitted (listed previously)
</code>```

I am using

```<code>kapt "com.android.databinding:compiler:2.2.0"
</code>```

Before I was using

```<code>androidProcessor "com.android.databinding:compiler:2.2.0"
</code>```

And it was working just fine... What I am doing wrong??

Thanks!

答:
For those still looking for a proper solution, Google has already fixed this issue in Android Studio 3.0 Canary 3 build.

Friday, June 2, 2017

We have just released Android Studio 3.0 Canary 3 to the Canary and
  Dev Channels. The Android Gradle Plugin 3.0.0-alpha3 was also released
  through maven.google.com. This release has fixes to Gradle, Kotlin,
  and many other fixes. We continue to fix bugs in all areas of Studio
  3.0 as we stabilize our features, so please continue to pass on feedback.

Working gradle configuration:

build.gradle (project)

```<code>buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
</code>```

build.gradle (module)

```<code>apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    dataBinding.enabled = true
}
dependencies {
    kapt "com.android.databinding:compiler:3.0.0-alpha3"
}
</code>```

Body:
I just started to use Android Studio 3.0.0, but every time I try to build my project I get this error:

Error:Circular dependency between the following tasks:
:app:compileDebugKotlin
+--- :app:dataBindingExportBuildInfoDebug
|    \--- :app:compileDebugKotlin (*)
\--- :app:kaptDebugKotlin
     \--- :app:dataBindingExportBuildInfoDebug (*)
(*) - details omitted (listed previously)

I am using

kapt "com.android.databinding:compiler:2.2.0"

Before I was using

androidProcessor "com.android.databinding:compiler:2.2.0"

And it was working just fine... What I am doing wrong??

Thanks!

Body:
For those still looking for a proper solution, Google has already fixed this issue in Android Studio 3.0 Canary 3 build.

Friday, June 2, 2017

We have just released Android Studio 3.0 Canary 3 to the Canary and
  Dev Channels. The Android Gradle Plugin 3.0.0-alpha3 was also released
  through maven.google.com. This release has fixes to Gradle, Kotlin,
  and many other fixes. We continue to fix bugs in all areas of Studio
  3.0 as we stabilize our features, so please continue to pass on feedback.

Working gradle configuration:

build.gradle (project)

buildscript {
    ext.kotlin_version = '1.1.2-4'
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

build.gradle (module)

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    dataBinding.enabled = true
}
dependencies {
    kapt "com.android.databinding:compiler:3.0.0-alpha3"
}


问:
what is the use of if else statements?
I don't quite understand the meaning of else if statements.

why not just to continue with the if statements in case one is false?

it works the same.

example with if only that will work the same with else if:

```<code>function testSize(num) {

  if (num < 5){

     return "Tiny";
  }

  if (num < 10){

    return "small";
  }

  return "Change Me";

}

testSize(7);
</code>```

答: A one way if statement takes an action if the specified condition is true.If the condition is false, nothing is done. But what if you want to take alternative actions when the conditions is false ? You can use a two-way if-else statement. The action that a two-way if-else statements specifies differ based on whether the condition is true or false.

Title: what is the use of if else statements?

Body:
I don't quite understand the meaning of else if statements.

why not just to continue with the if statements in case one is false?

it works the same.

example with if only that will work the same with else if:

function testSize(num) {

  if (num < 5){

     return "Tiny";
  }

  if (num < 10){

    return "small";
  }

  return "Change Me";

}

testSize(7);


问:
How to exclude text between two curly brackets with regex?
I am new to regular expressions, I have a text like this:

test{{this should not be selected and the curly brackets too}} but
  this one { or } should be selected.  So I want to exclude all text
  between an opening and closing curly brackets.

and I want this result

"test"

and

"but this one { or } should be selected.  So I want to exclude all text
  between an opening and closing curly brackets."

This is my expression I used:

```<code>$p = '/[a-zA-Z0-9#\' ]+(?![^{{]*}})/';
</code>```

But this excludes the single curly brackets.

I want to know how to include the single curly brackets with the text and exclude only text between two curly brackets

And please can you give me some good documentation about regex expression? I want to learn more about this.

答:
2 options:

easy: just consider the blocks between {{ }} as a split pattern

$validblocks = preg_split("/{{[\w .]+}}/", $str);

complicated: use groups and first capture rejcted pattern, then what remains:

(?<novalid>{{[\w ]+}})|(?<valid>{|[\w .]*|})

manage it as you want afterward. Example here: https://regex101.com/r/SK729o/2

Body:
I am new to regular expressions, I have a text like this:

test{{this should not be selected and the curly brackets too}} but
  this one { or } should be selected.  So I want to exclude all text
  between an opening and closing curly brackets.

and I want this result

"test"

and

"but this one { or } should be selected.  So I want to exclude all text
  between an opening and closing curly brackets."

This is my expression I used:

$p = '/[a-zA-Z0-9#\' ]+(?![^{{]*}})/';

But this excludes the single curly brackets.

I want to know how to include the single curly brackets with the text and exclude only text between two curly brackets

And please can you give me some good documentation about regex expression? I want to learn more about this.


问:
Changing single item in foreach loop
I would like to generate a navigation menu using PHP and its foreach loop. So since the "Home" item is a bit different than the others, I would like to call him, and change its style in some certain condition. This code below works fine for all other menu items except the homepage, as it adds array to the
 tag for some reason. Can you please show the mistake I make here?

```<code><?php
  $menu = array("Home" => "http://mywebsite.com", "Projects" => "/projects/", "About" => "/about/", "Contact" => "/contact/");
  foreach ($menu as $opis => $link)
  {
    if (strtolower($opis) == $_GET['go'])
    {
      $style = "class=\"active\"";
    }
    else
    {
      if (!$_GET['go'] || $_GET['go'] == "home")
      {
        $style[0] = "class=\"active\"";
        echo $style[0] . " ";
      }
    }
    echo "<li ".$style."><a href=".$link.">".$opis."</a></li>";
  }
?>
</code>```

答:
You need to set $style to ''. If you do not, you will keep class="active" on next iteration once set.

```<code>$menu = array("Home" => "http://mywebsite.com", "Projects" => "/projects/",
"About" => "/about/", "Contact" => "/contact/");
if(empty($_GET['go'])) $_GET['go'] = 'home';
foreach ($menu as $opis => $link)
{
    $style = (strtolower($opis) == $_GET['go']) ? "class=\"active\"" : '';
    echo "<li $style><a href='$link'>$opis</a></li>\n";
}
</code>```

Title: Changing single item in foreach loop

Body:
I would like to generate a navigation menu using PHP and its foreach loop. So since the "Home" item is a bit different than the others, I would like to call him, and change its style in some certain condition. This code below works fine for all other menu items except the homepage, as it adds array to the
 tag for some reason. Can you please show the mistake I make here?

<?php
  $menu = array("Home" => "http://mywebsite.com", "Projects" => "/projects/", "About" => "/about/", "Contact" => "/contact/");
  foreach ($menu as $opis => $link)
  {
    if (strtolower($opis) == $_GET['go'])
    {
      $style = "class=\"active\"";
    }
    else
    {
      if (!$_GET['go'] || $_GET['go'] == "home")
      {
        $style[0] = "class=\"active\"";
        echo $style[0] . " ";
      }
    }
    echo "
".$opis."
";
  }
?>

Body:
You need to set $style to ''. If you do not, you will keep class="active" on next iteration once set.

$menu = array("Home" => "http://mywebsite.com", "Projects" => "/projects/",
"About" => "/about/", "Contact" => "/contact/");
if(empty($_GET['go'])) $_GET['go'] = 'home';
foreach ($menu as $opis => $link)
{
    $style = (strtolower($opis) == $_GET['go']) ? "class=\"active\"" : '';
    echo "<li $style><a href='$link'>$opis</a></li>\n";
}


问:
chat room whit gif and emoji and image Java
I want to build a chat room whit java swing.

I want to have a component to show text, image, gif and emoji.

please help me to select a good component.

In first I choose JtextPane for this.Is it good?

答:
In first I choose JtextPane for this.Is it good?

Yes, I would use a JTextPane, with normal text (not HTML). With a JTextPane you can:

text with attributes.

align text to the right/left of the text pane

display icons using the insertIcon(...) method.

Read the section from the Swing tutorial on Text Component Features for some examples that use attributes when adding text.


问:
Outlook Interop AddressEntry Exception
I've written an outlook plugin that retrieves the sender's SMTP email address for a mailitem.  It is working fine on most machines, however, I have one machine (my new development machine) that throws a COMException every time it tries to resolve the SMTP address for an email from an exchange user.  Below is the code I'm using...

```<code>private string SenderEmail(MailItem item)
{
    if (item == null)
    {
        return "";
    }
    else
    {
        string senderEmail = string.Empty;

        if (item.SenderEmailType.ToUpper() == "EX")
            senderEmail = GetEmailAddressFromOU(item.SenderEmailAddress);
        else
            senderEmail = item.SenderEmailAddress;

         return senderEmail;
    }
}

private string GetEmailAddressFromOU(string ouName)
{
    string emailAddress = string.Empty;

    NameSpace oNS = ((Microsoft.Office.Interop.Outlook.Application)OutlookAppObj).GetNamespace("MAPI");
    Recipient recip = oNS.CreateRecipient(ouName);
    recip.Resolve();
    ExchangeUser exUser = recip.AddressEntry.GetExchangeUser();

    emailAddress = exUser.PrimarySmtpAddress;

    Marshal.ReleaseComObject(exUser);
    Marshal.ReleaseComObject(recip);
    Marshal.ReleaseComObject(oNS);

    return emailAddress;
}
</code>```

The following COMException occurs when accessing the AddressEntry property of the Recipient object:

Message = "The attempted operation failed.  An object could not be found."

I'm using Windows 7 (64bit), using Outlook 2010, however this same code works on other machines with the same OS and Outlook version.  It also works fine on my previous development machine which was also Windows 7 (32bit) and Outlook 2010.

I've searched StackOverflow and Google for any resolution, but haven't found any.

Can anyone shed some light on this problem?

答: Still not sure what was causing the problem, but deleting all my E-Mail accounts in Outlook and re-adding them, fixed the problem.</p>

Title: Outlook Interop AddressEntry Exception

Body:
I've written an outlook plugin that retrieves the sender's SMTP email address for a mailitem.  It is working fine on most machines, however, I have one machine (my new development machine) that throws a COMException every time it tries to resolve the SMTP address for an email from an exchange user.  Below is the code I'm using...

private string SenderEmail(MailItem item)
{
    if (item == null)
    {
        return "";
    }
    else
    {
        string senderEmail = string.Empty;

        if (item.SenderEmailType.ToUpper() == "EX")
            senderEmail = GetEmailAddressFromOU(item.SenderEmailAddress);
        else
            senderEmail = item.SenderEmailAddress;

         return senderEmail;
    }
}

private string GetEmailAddressFromOU(string ouName)
{
    string emailAddress = string.Empty;

    NameSpace oNS = ((Microsoft.Office.Interop.Outlook.Application)OutlookAppObj).GetNamespace("MAPI");
    Recipient recip = oNS.CreateRecipient(ouName);
    recip.Resolve();
    ExchangeUser exUser = recip.AddressEntry.GetExchangeUser();

    emailAddress = exUser.PrimarySmtpAddress;

    Marshal.ReleaseComObject(exUser);
    Marshal.ReleaseComObject(recip);
    Marshal.ReleaseComObject(oNS);

    return emailAddress;
}

The following COMException occurs when accessing the AddressEntry property of the Recipient object:

Message = "The attempted operation failed.  An object could not be found."

I'm using Windows 7 (64bit), using Outlook 2010, however this same code works on other machines with the same OS and Outlook version.  It also works fine on my previous development machine which was also Windows 7 (32bit) and Outlook 2010.

I've searched StackOverflow and Google for any resolution, but haven't found any.

Can anyone shed some light on this problem?


问:
Why does scrolling a scrollview increase memory usage a lot?
I have a acrollview which contains maybe 15 rows in imageview (own special listview). Each row contains text and cross bitmap.

When I first create the scrollview there is almost no memory usage, but at the moment I touch it to scroll, memory usage is increased by ~2 MB.

This tends to make GC run which makes scrolling very choppy.

I'm reusing the views, so this can not be it. Any ideas?

I set bitmap into imageview immediately, not from internet, I generated bitmap from user data. sometimes 25 or more lines.

Can I somehow clear memoryusages? and Init with need value actualy?

I thing so code it's unnecessary, but If you want/need write.

If I scrool too long app crashed on outOfmemory error

===================EDIT===================================

I I found out I generated new image on every touch (as it's the same)..

now increase less, but increase.

答:
A best practice in Android for such cases would be to use a Recycler View with an Adapter. This will keep your memory in check.

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

Also check out this great video from udacity
https://www.youtube.com/watch?v=-VPM6ICgCk8


问:
Generating random password into input with input length using Javascript
```<code><form name="pgenerate">
<input type="text" size=18 name="output">
<input type="button" value="Generate Password" ><br />
<b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
</form>
</code>```

How can i make a random password generator that will generate password inside an input you can use in you projects or systems

答:
var keylist="abcdefghijklmnopqrstuvwxyz123456789"
var temp=''

function generatepass(plength){
temp=''
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
return temp
}

function populateform(enterlength){
document.pgenerate.output.value=generatepass(enterlength)
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form name="pgenerate">
<input type="text" size=18 name="output">
<input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br />
<b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
</form></code>```

Body:
<form name="pgenerate">
<input type="text" size=18 name="output">
<input type="button" value="Generate Password" >

Password Length: <input type="text" name="thelength" size=3 value="7">
</form>

How can i make a random password generator that will generate password inside an input you can use in you projects or systems

Body:
var keylist="abcdefghijklmnopqrstuvwxyz123456789"
var temp=''

function generatepass(plength){
temp=''
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
return temp
}

function populateform(enterlength){
document.pgenerate.output.value=generatepass(enterlength)
}

<form name="pgenerate">
<input type="text" size=18 name="output">
<input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br />
<b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
</form>


问:
How to read markdown text and style it to html?
For example, I write news content in markdown text and when I request via PHP, then PHP will read markdown text and convert to html. Is it possible?</p>

答:
You could use the ParseDown lib for PHP. I don't know a native way to do this without external library.

Follow the instruction of the gitHub repository for the installation in your project (with composer or just include the file).

After that, it's quite easy to use.

for example, I got markdown README.md file to parse to html :

```<code>include('Parsedown.php');

$readme = file_get_contents('README.md');
$Parsedown = new Parsedown();

$html = $Parsedown->text($readme);
</code>```

Hope it helps.

Body:
You could use the ParseDown lib for PHP. I don't know a native way to do this without external library.

Follow the instruction of the gitHub repository for the installation in your project (with composer or just include the file).

After that, it's quite easy to use.

for example, I got markdown README.md file to parse to html :

include('Parsedown.php');

$readme = file_get_contents('README.md');
$Parsedown = new Parsedown();

$html = $Parsedown->text($readme);

Hope it helps.


问:
How to make same height of all responsive images in a row
The first image of the row doesn't have the same height as the other ones. I am using Bootstrap .img-responsive.

HTML

```<code><div class="row">
    <div class="down-content">
        <div class="haber">
            <!--HABER 1-->
            <div class="col-sm-3">
                <div id="haber1">
                    <div id="haberimg1">
                        <img class="img-responsive" src="http://www.avukatwebsite.net/public/_uploads/photos/temalar/avukat-web-site-tema-1.jpg" >
                    </div>
                    <div id="haberyazi1">
                        <h3>Kanser Affetmedi...</h3>
                        <p>Sanssiz genc Kanser yüzünden öldü...</p>
                        <button type="button" class="btn">Devamini Oku...</button>
                    </div>
                </div>
            </div>
            <!--HABER 2-->
            <div class="col-sm-3">
                <div id="haber2">
                    <div id="haberimg2">
                        <img class="img-responsive" src="http://medicare.bold-themes.com/clinic/wp-content/uploads/sites/2/2015/12/shutterstock_288977717-1200x800.jpg" >
                    </div>
                    <div id="haberyazi2">
                        <h3>Sizofreni Salgini</h3>
                        <p>Türkiyede ki Sizofren sayisinda artis görüldü...</p>
                        <button type="button" class="btn">Devamini Oku...</button>
                    </div>
                </div>
            </div>
            /* we deleted the other parts because of mostly code problem */
        </div>
        <!--HABER BÖLÜMÜ BITIS-->
    </div>
</div>
</code>```

Bootstrap CSS

```<code>.img-responsive,
.thumbnail > img,
.thumbnail a > img,
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
    display: block;
    max-width: 100%;
    height: auto;
}
</code>```

This is the issue:

答:
There are a number of solutions. Here is a couple of similar solutions. First you would need to create a div that scales responsively. This can be achieved with:

```<code>.img-wrap {
  height:0;
  // adjust the padding to change the aspect ratio of the div
  padding-bottom:60%;
}
</code>```

you can then either add a background image to the .image-wrap element with background-size:cover. Or you could place an image inside .image-wrap and then position:absolute; it inside .image-wrap and add object-fit: cover; width: 100%; height: 100%;.

Body:
The first image of the row doesn't have the same height as the other ones. I am using Bootstrap .img-responsive.

HTML

Kanser Affetmedi...

Sanssiz genc Kanser yüzünden öldü...

                        <button type="button" class="btn">Devamini Oku...</button>

Sizofreni Salgini

Türkiyede ki Sizofren sayisinda artis görüldü...

                        <button type="button" class="btn">Devamini Oku...</button>

            /* we deleted the other parts because of mostly code problem */

Bootstrap CSS

.img-responsive,
.thumbnail > img,
.thumbnail a > img,
.carousel-inner > .item > img,
.carousel-inner > .item > a > img {
    display: block;
    max-width: 100%;
    height: auto;
}

This is the issue:

Body:
There are a number of solutions. Here is a couple of similar solutions. First you would need to create a div that scales responsively. This can be achieved with:

.img-wrap {
  height:0;
  // adjust the padding to change the aspect ratio of the div
  padding-bottom:60%;
}

you can then either add a background image to the .image-wrap element with background-size:cover. Or you could place an image inside .image-wrap and then position:absolute; it inside .image-wrap and add object-fit: cover; width: 100%; height: 100%;.

ContentLicense: CC BY-SA 4.0


问:
DataGridView deleting row save
my problem is that i have datagridview, and i select row i click delete button but when i refresh it is back

```<code>Private Sub btnDlt_Click(sender As Object, e As EventArgs) Handles btnDlt.Click
    For Each row As DataGridViewRow In dgwData.SelectedRows
        dgwData.Rows.Remove(row)
        SQL.DBDA.Update(SQL.DBDT)
    Next
End Sub
</code>```

and my upadte is working good, it is saving everything, here is code

```<code>    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
    If MsgBox("Nazaj si prajete uložiť tieto zmeny?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        SQL.DBDA.Update(SQL.DBDT)
        loadGrid()
        btnUpdate.Enabled = False
        If SQL.hasException() Then
            Exit Sub
        End If
    Else
        btnUpdate.Enabled = False
        loadGrid()
    End If

End Sub
</code>```

答: The problem should be with your datasource, check your delete query if it work fine. </p>

Title: DataGridView deleting row save

Body:
my problem is that i have datagridview, and i select row i click delete button but when i refresh it is back

Private Sub btnDlt_Click(sender As Object, e As EventArgs) Handles btnDlt.Click
    For Each row As DataGridViewRow In dgwData.SelectedRows
        dgwData.Rows.Remove(row)
        SQL.DBDA.Update(SQL.DBDT)
    Next
End Sub

and my upadte is working good, it is saving everything, here is code

    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
    If MsgBox("Nazaj si prajete uložiť tieto zmeny?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        SQL.DBDA.Update(SQL.DBDT)
        loadGrid()
        btnUpdate.Enabled = False
        If SQL.hasException() Then
            Exit Sub
        End If
    Else
        btnUpdate.Enabled = False
        loadGrid()
    End If

End Sub


答: No need to reinvent the wheel. Check out this library: https://www.npmjs.com/package/generate-password which does exactly what you want.</p>

Title: Generating random password into input with input length using Javascript


问:
Why do you have to specify a type for pointers?
Why do you have to set a type for pointers? Aren’t they just a placeholder for addresses and all those addresses? Therefore, won't all pointers no matter what type specified occupy an equal size of memory?</p>

答:
You don't have to specify a type for pointers.  You can use void* everywhere, which would force you to insert an explicit type cast every single time you read something from the address pointed by the pointer, or write something to that address, or simply increment/decrement or otherwise manipulate the value of the pointer.

But people decided a long time ago that they were tired of this way of programming, and preferred typed pointers that

do not require casts

do not require always having to know the size of the pointed type (which is an issue that gets even more complicated when proper memory alignment has to be taken into consideration)

prevent you from accidentally accessing the wrong data type or advancing the pointer by the wrong number of bytes.

And yes, indeed, all data pointers, no matter what their type, occupy the same amount of memory, which is usually 4 bytes on 32-bit systems, and 8 bytes on 64-bit systems.  The type of a data pointer has nothing to do with the amount of memory occupied by the pointer, and that's because no type information is stored with the pointer; the pointer type is only useful to humans and to the compiler, not to the machine.