问:
Xamarin.Forms How do I disable click animation on ListView
I am currently developed an app that use a ListView.
This app is created with Xamarin.Forms and was originally mend to be used on Android and iOS. However we have decided to prepare a UWP project as well.

The problem is, when clicking on an item from the listview, a click animation happened in UWP applications:

See this image what I mean by the animation:
example UWP click animation

However this animation doesn't look well in our project.

The problem is:
How can the click animation on a listview item been disabled ?
We just want to become a listview without any animations. Just a plain flat list, while keeping eventHandlers.

In another Stackoverflow forum, they told us to disable the control. But that renders the control completely useless since we can't get the selecteditem + it disables scrolling.

I also found this useful forum, however this instructions are for UAP (Win8 app):
https://nicksnettravels.builttoroam.com/post/2014/05/25/Remove-TapMouse-Down-Animations-on-GridView-and-ListView-for-Windows-81.aspx

Can someone please share an example or sample code how to disable the animation?

答:
You need to create a custom list view renderer and apply a custom style on it.

Create a derived ListView:

```<code>namespace MyApp.Controls
{
    public class MyListView : Xamarin.Forms.ListView
    {
    }
}
</code>```

In your views change the ListView to your derived control:

```<code> <?xml version="1.0" encoding="utf-8" ?>
 <ContentView
      xmlns="http://xamarin.com/schemas/2014/forms"
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      xmlns:controls="clr-namespace:MyApp.Controls"
      x:Class="MyApp.MyView">
      <controls:MyListView
           ItemsSource="{Binding ListSource}"
           SelectionMode="None"
           SeparatorVisibility="None">
          // ...
          // template
          // ..
    </controls:CustomListView>
</ContentView>
</code>```

In your UWP project create a list view render:

```<code>[assembly: ExportRenderer(typeof(MyListView), typeof(MyListViewRenderer))]
namespace MyApp
{
    class MyListViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);
            if (Control is Windows.UI.Xaml.Controls.ListView listView)
            {
                listView.ItemContainerStyle = (Windows.UI.Xaml.Style)MyApp.App.Current.Resources["CustomListViewItem"];
            }
        }
    }
}
</code>```

Now you'll need to define the above CustomListViewItem style.
The default styles for windows controls are defined in the generic.xaml file, and can be found on your following local path:

```<code>C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.18362.0\Generic
</code>```

Within it you'll find the default list view item style which is called ListViewItemExpanded, you need to modify its style and load it to a resource dictionary.
Here's a shortened version without the animation (save it to CustomListViewItem.xaml):

```<code><ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

</ResourceDictionary>
</code>```

Notice that <PointerDownThemeAnimation TargetName="ContentPresenter" /> is commented out  in the pressed visual state.

Now load that resource to your app:

```<code><Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Styles/CustomListViewItem.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
</code>```

You might need to further tweak the style, but basically this is it.

Btw this same method can be used to tweak the appearance of any native control in UWP.

Body:
You need to create a custom list view renderer and apply a custom style on it.

Create a derived ListView:

namespace MyApp.Controls
{
    public class MyListView : Xamarin.Forms.ListView
    {
    }
}

In your views change the ListView to your derived control:

 <?xml version="1.0" encoding="utf-8" ?>
 <ContentView
      xmlns="http://xamarin.com/schemas/2014/forms"
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
      xmlns:controls="clr-namespace:MyApp.Controls"
      x:Class="MyApp.MyView">
      <controls:MyListView
           ItemsSource="{Binding ListSource}"
           SelectionMode="None"
           SeparatorVisibility="None">
          // ...
          // template
          // ..
    </controls:CustomListView>
</ContentView>

In your UWP project create a list view render:

[assembly: ExportRenderer(typeof(MyListView), typeof(MyListViewRenderer))]
namespace MyApp
{
    class MyListViewRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);
            if (Control is Windows.UI.Xaml.Controls.ListView listView)
            {
                listView.ItemContainerStyle = (Windows.UI.Xaml.Style)MyApp.App.Current.Resources["CustomListViewItem"];
            }
        }
    }
}

Now you'll need to define the above CustomListViewItem style.
The default styles for windows controls are defined in the generic.xaml file, and can be found on your following local path:

C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.18362.0\Generic

Within it you'll find the default list view item style which is called ListViewItemExpanded, you need to modify its style and load it to a resource dictionary.
Here's a shortened version without the animation (save it to CustomListViewItem.xaml):

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    <Style x:Key="CustomListViewItem" TargetType="ListViewItem">
        <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
        <Setter Property="BorderBrush" Value="{x:Null}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
        <Setter Property="TabNavigation" Value="Local" />
        <Setter Property="IsHoldingEnabled" Value="True" />
        <Setter Property="Padding" Value="0,0,0,0" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}" />
        <Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}" />
        <Setter Property="AllowDrop" Value="False" />
        <Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
        <Setter Property="FocusVisualMargin" Value="0" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListViewItem">
                    <Grid x:Name="ContentBorder"
              Control.IsTemplateFocusTarget="True"
              FocusVisualMargin="{TemplateBinding FocusVisualMargin}"
              Background="{TemplateBinding Background}"
              BorderBrush="{TemplateBinding BorderBrush}"
              BorderThickness="{TemplateBinding BorderThickness}"
              CornerRadius="{TemplateBinding CornerRadius}"
              RenderTransformOrigin="0.5,0.5">

                        <Grid.RenderTransform>
                            <ScaleTransform x:Name="ContentBorderScale" />
                        </Grid.RenderTransform>

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal">

                                    <Storyboard>
                                        <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="PointerOver">

                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0"
                                            To="1" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListLowBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheck" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="Pressed">

                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0"
                                            To="1" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListMediumBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheck" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <!--<PointerDownThemeAnimation TargetName="ContentPresenter" />-->
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="Selected">

                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="MultiSelectCheck"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0:0:0"
                                            To="1" />
                                        <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0"
                                            To="1" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentLowBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheck" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="PointerOverSelected">

                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="MultiSelectCheck"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0:0:0"
                                            To="1" />
                                        <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0"
                                            To="1" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentMediumBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheck" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="PressedSelected">

                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="MultiSelectCheck"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0:0:0"
                                            To="1" />
                                        <DoubleAnimation Storyboard.TargetName="BorderBackground"
                                            Storyboard.TargetProperty="Opacity"
                                            Duration="0"
                                            To="1" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderBackground" Storyboard.TargetProperty="Fill">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightListAccentHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheck" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <PointerDownThemeAnimation TargetName="ContentPresenter" />
                                    </Storyboard>
                                </VisualState>

                            </VisualStateGroup>

                            <VisualStateGroup x:Name="DisabledStates">
                                <VisualState x:Name="Enabled" />

                                <VisualState x:Name="Disabled">

                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="ContentBorder"
                        Storyboard.TargetProperty="Opacity"
                        Duration="0"
                        To="{ThemeResource ListViewItemDisabledThemeOpacity}" />
                                    </Storyboard>
                                </VisualState>

                            </VisualStateGroup>

                            <VisualStateGroup x:Name="MultiSelectStates">
                                <VisualState x:Name="MultiSelectDisabled">

                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheckBoxTransform" Storyboard.TargetProperty="X">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                            <SplineDoubleKeyFrame KeyTime="0:0:0.333" Value="-32" KeySpline="0.1,0.9,0.2,1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectClipTransform" Storyboard.TargetProperty="X">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                                            <SplineDoubleKeyFrame KeyTime="0:0:0.333" Value="32" KeySpline="0.1,0.9,0.2,1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterTranslateTransform" Storyboard.TargetProperty="X">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="32" />
                                            <SplineDoubleKeyFrame KeyTime="0:0:0.333" Value="0" KeySpline="0.1,0.9,0.2,1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                            <DiscreteObjectKeyFrame KeyTime="0:0:0.333" Value="Collapsed" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>

                                <VisualState x:Name="MultiSelectEnabled">

                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheckBoxTransform" Storyboard.TargetProperty="X">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="-32" />
                                            <SplineDoubleKeyFrame KeyTime="0:0:0.333" Value="0" KeySpline="0.1,0.9,0.2,1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectClipTransform" Storyboard.TargetProperty="X">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="32" />
                                            <SplineDoubleKeyFrame KeyTime="0:0:0.333" Value="0" KeySpline="0.1,0.9,0.2,1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterTranslateTransform" Storyboard.TargetProperty="X">
                                            <EasingDoubleKeyFrame KeyTime="0:0:0" Value="-32" />
                                            <SplineDoubleKeyFrame KeyTime="0:0:0.333" Value="0" KeySpline="0.1,0.9,0.2,1" />
                                        </DoubleAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectSquare" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MultiSelectCheck" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenterGrid" Storyboard.TargetProperty="Margin">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="32,0,0,0" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>

                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle x:Name="BorderBackground"
                            IsHitTestVisible="False"
                            Fill="{ThemeResource SystemControlHighlightListAccentLowBrush}"
                            Opacity="0"
                            Control.IsTemplateFocusTarget="True" />
                        <Grid x:Name="ContentPresenterGrid" Background="Transparent" Margin="0,0,0,0">
                            <Grid.RenderTransform>
                                <TranslateTransform x:Name="ContentPresenterTranslateTransform" />
                            </Grid.RenderTransform>
                            <ContentPresenter x:Name="ContentPresenter"
                                ContentTransitions="{TemplateBinding ContentTransitions}"
                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                Content="{TemplateBinding Content}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Margin="{TemplateBinding Padding}" />

                        </Grid>
                        <!-- The 'Xg' text simulates the amount of space one line of text will occupy.
                             In the DataPlaceholder state, the Content is not loaded yet so we
                             approximate the size of the item using placeholder text. -->
                        <TextBlock x:Name="PlaceholderTextBlock"
                            Opacity="0"
                            Text="Xg"
                            Foreground="{x:Null}"
                            Margin="{TemplateBinding Padding}"
                            IsHitTestVisible="False"
                            AutomationProperties.AccessibilityView="Raw" />
                        <Rectangle x:Name="PlaceholderRect" Visibility="Collapsed" Fill="{ThemeResource ListViewItemPlaceholderBackground}" />
                        <Border x:Name="MultiSelectSquare"
                            BorderBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                            BorderThickness="2"
                            Width="20"
                            Height="20"
                            Margin="12,0,0,0"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Left"
                            Visibility="Collapsed">
                            <Border.Clip>
                                <RectangleGeometry Rect="0,0,20,20">
                                    <RectangleGeometry.Transform>
                                        <TranslateTransform x:Name="MultiSelectClipTransform" />
                                    </RectangleGeometry.Transform>
                                </RectangleGeometry>
                            </Border.Clip>
                            <Border.RenderTransform>
                                <TranslateTransform x:Name="MultiSelectCheckBoxTransform" />
                            </Border.RenderTransform>
                            <FontIcon x:Name="MultiSelectCheck"
                                FontFamily="{ThemeResource SymbolThemeFontFamily}"
                                Glyph="&#xE73E;"
                                FontSize="16"
                                Foreground="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
                                Visibility="Collapsed"
                                Opacity="0" />
                        </Border>
                        <Border x:Name="MultiArrangeOverlayTextBorder"
                            Opacity="0"
                            IsHitTestVisible="False"
                            Margin="12,0,0,0"
                            MinWidth="20"
                            Height="20"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Left"
                            Background="{ThemeResource SystemControlBackgroundAccentBrush}"
                            BorderThickness="2"
                            BorderBrush="{ThemeResource SystemControlBackgroundChromeWhiteBrush}">
                            <TextBlock x:Name="MultiArrangeOverlayText"
                  Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.DragItemsCount}"
                  Style="{ThemeResource CaptionTextBlockStyle}"
                  IsHitTestVisible="False"
                  Opacity="0"
                  VerticalAlignment="Center"
                  HorizontalAlignment="Center"
                  AutomationProperties.AccessibilityView="Raw" />
                        </Border>

                    </Grid>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

Notice that <PointerDownThemeAnimation TargetName="ContentPresenter" /> is commented out  in the pressed visual state.

Now load that resource to your app:

<Application
    x:Class="MyApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Styles/CustomListViewItem.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

You might need to further tweak the style, but basically this is it.

Btw this same method can be used to tweak the appearance of any native control in UWP.


来源: stackexchange

问:
git config: list all variables and their default values
Similar to the MySQL show variables command that shows all variables and not just the ones defined in my.ini, I would like to see a list of all config variables in git along with their default values, and not just those defined in my ~/.gitconfig.

Is this possible?

答:
If you have git 2.19 or newer

```<code>git help -c
</code>```

Will list all known keys that can be used for configuration

ContentLicense: CC BY-SA 3.0

Body:
If you have git 2.19 or newer

git help -c

Will list all known keys that can be used for configuration

ContentLicense: CC BY-SA 4.0


问:
"Key is invalid" message on GitHub
I have generated SSH keys for a new server installation according to the procedure outlined here. However, when I copy the contents of id_rsa.pub to my keys list on GitHub, I get the error message "Key is invalid. Ensure you've copied the file correctly."

The generated key is valid, and I am copying it exactly as is (all in one line with no whitespace at the beginning/end).

Anybody have an idea what could be going on?

答:
Someone suggested to use  $ vi ~/.ssh/id_rsa.pub however it didn't work for me.

So instead of that ,  I used $ cat ~/.ssh/id_rsa.pub command on windows machine to print out on the terminal then copy it.

Title: "Key is invalid" message on GitHub


问:
Codeigniter 3.0 phpunit testing not working
I tried to add phpunit testing code to my already built up site using http://blog.a-way-out.net/blog/2015/06/12/codeigniter3-phpunit/
but its throw error:</p>

```<code>1) Homemodel_test::test_When_you_get_all_news_Then_you_get_one_item
LogicException: CodeIgniter instance is not instantiated yet. You can't use `$th
is->simple_cache` at the moment. Please fix your test code.
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestNull
CodeIgniter.php:18
E:\xampp\htdocs\CodeIgniter\application\helpers\language_helper.php:10
E:\xampp\htdocs\CodeIgniter\application\core\ROCKERS_Controller.php:51
E:\xampp\htdocs\CodeIgniter\application\controllers\Home.php:51
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:292
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:215
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:126
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestCase
.php:106
E:\xampp\htdocs\CodeIgniter\application\tests\models\home_model_test.php:25
FAILURES!
</code>```

答:
I ran into this issue also, but in a bit different scenario. I noticed that context is "lost" after calling $this->request()

```<code>$CI =& get_instance();
$CI->load->model('Random_model');
$CI->Random_model->save($data);

$output = $this->request('POST', 'https://example.com/random', $data);

// Now if I want to load model I need to call get_instance() again
$CI =& get_instance();
$CI->load->model('Other_model');
</code>```

If I do not call get_instance() again. I will get error:

[phpunit] LogicException: CodeIgniter instance is not instantiated
  yet. You can't use $this->load at the moment. Please fix your test
  code.

Body:
I tried to add phpunit testing code to my already built up site using http://blog.a-way-out.net/blog/2015/06/12/codeigniter3-phpunit/
but its throw error:

1) Homemodel_test::test_When_you_get_all_news_Then_you_get_one_item
LogicException: CodeIgniter instance is not instantiated yet. You can't use `$th
is->simple_cache` at the moment. Please fix your test code.
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestNull
CodeIgniter.php:18
E:\xampp\htdocs\CodeIgniter\application\helpers\language_helper.php:10
E:\xampp\htdocs\CodeIgniter\application\core\ROCKERS_Controller.php:51
E:\xampp\htdocs\CodeIgniter\application\controllers\Home.php:51
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:292
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:215
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestRequ
est.php:126
E:\xampp\htdocs\CodeIgniter\application\tests\_ci_phpunit_test\CIPHPUnitTestCase
.php:106
E:\xampp\htdocs\CodeIgniter\application\tests\models\home_model_test.php:25
FAILURES!

Body:
I ran into this issue also, but in a bit different scenario. I noticed that context is "lost" after calling $this->request()

$CI =& get_instance();
$CI->load->model('Random_model');
$CI->Random_model->save($data);

$output = $this->request('POST', 'https://example.com/random', $data);

// Now if I want to load model I need to call get_instance() again
$CI =& get_instance();
$CI->load->model('Other_model');

If I do not call get_instance() again. I will get error:

[phpunit] LogicException: CodeIgniter instance is not instantiated
  yet. You can't use $this->load at the moment. Please fix your test
  code.


问:
ORA-00904: invalid identifier
I tried to write the following inner join query using an Oracle database:

```<code> SELECT Employee.EMPLID as EmpID,
        Employee.FIRST_NAME AS Name,
        Team.DEPARTMENT_CODE AS TeamID,
        Team.Department_Name AS teamname
 FROM PS_TBL_EMPLOYEE_DETAILS Employee
 INNER JOIN PS_TBL_DEPARTMENT_DETAILS Team
 ON Team.DEPARTMENT_CODE = Employee.DEPTID
</code>```

That gives the below error:

```<code> INNER JOIN PS_TBL_DEPARTMENT_DETAILS Team ON Team.DEPARTMENT_CODE = Employee.DEPTID
                                              *
ERROR at line 4:
ORA-00904: "TEAM"."DEPARTMENT_CODE": invalid identifier
</code>```

The DDL of one table is:

```<code>CREATE TABLE "HRMS"."PS_TBL_DEPARTMENT_DETAILS"
(
  "Company Code" VARCHAR2(255),
  "Company Name" VARCHAR2(255),
  "Sector_Code" VARCHAR2(255),
  "Sector_Name" VARCHAR2(255),
  "Business_Unit_Code" VARCHAR2(255),
  "Business_Unit_Name" VARCHAR2(255),
  "Department_Code" VARCHAR2(255),
  "Department_Name" VARCHAR2(255),
  "HR_ORG_ID" VARCHAR2(255),
  "HR_ORG_Name" VARCHAR2(255),
  "Cost_Center_Number" VARCHAR2(255),
  " " VARCHAR2(255)
)
SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS
</code>```

答:
Are you sure you have a column DEPARTEMENT_CODE on your table PS_TBL_DEPARTMENT_DETAILS

More informations about your ERROR

ORA-00904:    string: invalid identifier
      Cause:    The column name entered is either missing or invalid.
      Action:   Enter a valid column name. A valid column name must begin with a
  letter,
      be less than or equal to 30 characters, and consist of only
  alphanumeric characters and
      the special characters $, _, and #.
      If it contains other characters, then it must be enclosed in d  double
  quotation marks.
      It may not be a reserved word.

Title: ORA-00904: invalid identifier

Body:
I tried to write the following inner join query using an Oracle database:

 SELECT Employee.EMPLID as EmpID,
        Employee.FIRST_NAME AS Name,
        Team.DEPARTMENT_CODE AS TeamID,
        Team.Department_Name AS teamname
 FROM PS_TBL_EMPLOYEE_DETAILS Employee
 INNER JOIN PS_TBL_DEPARTMENT_DETAILS Team
 ON Team.DEPARTMENT_CODE = Employee.DEPTID

That gives the below error:

 INNER JOIN PS_TBL_DEPARTMENT_DETAILS Team ON Team.DEPARTMENT_CODE = Employee.DEPTID
                                              *
ERROR at line 4:
ORA-00904: "TEAM"."DEPARTMENT_CODE": invalid identifier

The DDL of one table is:

CREATE TABLE "HRMS"."PS_TBL_DEPARTMENT_DETAILS"
(
  "Company Code" VARCHAR2(255),
  "Company Name" VARCHAR2(255),
  "Sector_Code" VARCHAR2(255),
  "Sector_Name" VARCHAR2(255),
  "Business_Unit_Code" VARCHAR2(255),
  "Business_Unit_Name" VARCHAR2(255),
  "Department_Code" VARCHAR2(255),
  "Department_Name" VARCHAR2(255),
  "HR_ORG_ID" VARCHAR2(255),
  "HR_ORG_Name" VARCHAR2(255),
  "Cost_Center_Number" VARCHAR2(255),
  " " VARCHAR2(255)
)
SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS


问:
How to get the actual utterance text of an Alexa skill intent using JOVO framework
Is there a way to get the actual Alexa utterance (the actual question or phrase user has asked) using JOVO? I need to alter the speech output based on that. Here is a use case scenario:

Variations:

Utterance: How many active coupons

Alexa: At present, you have 2 active coupons. Do you want more details?

Utterance: Yes

Alexa: Currently you have 2 active coupons running. WINTER20 with a 10 per cent discount, which expires on February 20, 2020. SPRING20 with a flat INR 250 discount on all products above INR 1000. Expires on April 30, 2020.

Utterance: Get my coupon details

Alexa: Currently you have 2 active coupons running. WINTER20 with a 10 per cent discount, which expires on February 20, 2020. SPRING20 with a flat INR 250 discount on all products above INR 1000. Expires on April 30, 2020.

答:
You can't get the exact text or question that a user asked from Alexa. Your skill will only receive the intent name and any associated slot values (if filled).

However, you could adapt your interaction model to fit your use-cases. For example, you could create an GetActiveCouponIntent and GetCouponDetailsIntent with different sample utterances.
Then, if the user triggers the GetActiveCouponIntent intent, you can set a session attribute indicating the state. If the user then triggers the AMAZON.YesIntent you can evaluate the state attribute and change the output accordingly.


问:
Access first name of user in WooCommerce account acitivation mail (DOI via WooCommerce Germanized)
We have a custom registration page for our WooCommerce site which is based on a Business Bloomer shortcode and added an input field for the first name of the user. The code within our functions.php looks like this:

```<code>/**
 * @snippet       WooCommerce User Registration Shortcode
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

// THIS WILL CREATE A NEW SHORTCODE: [wc_reg_form_bbloomer]
add_shortcode('wc_reg_form_bbloomer', 'bbloomer_separate_registration_form');

function bbloomer_separate_registration_form()
{
    if (is_admin()) return;
    if (is_user_logged_in()) return;
    ob_start();

    // NOTE: THE FOLLOWING <FORM></FORM> IS COPIED FROM woocommerce\templates\myaccount\form-login.php
    // IF WOOCOMMERCE RELEASES AN UPDATE TO THAT TEMPLATE, YOU MUST CHANGE THIS ACCORDINGLY

?>

      <form method="post" class="woocommerce-form woocommerce-form-register register" <?php do_action('woocommerce_register_form_tag'); ?> >

            <?php do_action('woocommerce_register_form_start'); ?>

            <?php if ('no' === get_option('woocommerce_registration_generate_username')): ?>

                <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                    <label for="reg_username"><?php esc_html_e('Username', 'woocommerce'); ?> <span class="required">*</span></label>
                    <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="reg_username" autocomplete="username" value="<?php echo (!empty($_POST['username'])) ? esc_attr(wp_unslash($_POST['username'])) : ''; ?>" /><?php // @codingStandardsIgnoreLine
         ?>
                </p>

            <?php
    endif; ?>

            <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                <label for="reg_email"><?php esc_html_e('Email address', 'woocommerce'); ?> <span class="required">*</span></label>
                <input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" autocomplete="email" value="<?php echo (!empty($_POST['email'])) ? esc_attr(wp_unslash($_POST['email'])) : ''; ?>" /><?php // @codingStandardsIgnoreLine
     ?>
            </p>

            <?php if ('no' === get_option('woocommerce_registration_generate_password')): ?>

                <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
                    <label for="reg_password"><?php esc_html_e('Password', 'woocommerce'); ?> <span class="required">*</span></label>
                    <input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password" autocomplete="new-password" />
                </p>

            <?php
    else: ?>

                <p><?php esc_html_e('A password will be sent to your email address.', 'woocommerce'); ?></p>

            <?php
    endif; ?>

            <?php do_action('woocommerce_register_form'); ?>

            <p class="woocommerce-FormRow form-row">
                <?php wp_nonce_field('woocommerce-register', 'woocommerce-register-nonce'); ?>
                <button type="submit" class="woocommerce-Button woocommerce-button button woocommerce-form-register__submit" name="register" value="<?php esc_attr_e('Register', 'woocommerce'); ?>"><?php esc_html_e('Register', 'woocommerce'); ?></button>
            </p>

            <?php do_action('woocommerce_register_form_end'); ?>

        </form>

   <?php
    return ob_get_clean();
}

/**
 * @snippet       Add First to Register Form - WooCommerce
 * @sourcecode    https://businessbloomer.com/?p=21974
 * @author        Rodolfo Melogli
 * @credits       Claudio SM Web
 * @compatible    WC 3.5.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

///////////////////////////////
// 1. ADD FIELDS

add_action( 'woocommerce_register_form_start', 'bbloomer_add_name_woo_account_registration' );

function bbloomer_add_name_woo_account_registration() {
    ?>

    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
    <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
    </p>

    <div class="clear"></div>

    <?php
}

///////////////////////////////
// 2. VALIDATE FIELDS

add_filter( 'woocommerce_registration_errors', 'bbloomer_validate_name_fields', 10, 3 );

function bbloomer_validate_name_fields( $errors, $username, $email ) {
    if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
        $errors->add( 'billing_first_name_error', __( '<strong>Achtung</strong>: Vorname ist ein Pflichtfeld!', 'woocommerce' ) );
    }
    return $errors;
}

///////////////////////////////
// 3. SAVE FIELDS

add_action( 'woocommerce_created_customer', 'bbloomer_save_name_fields' );

function bbloomer_save_name_fields( $customer_id ) {
    if ( isset( $_POST['billing_first_name'] ) ) {
        update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
        update_user_meta( $customer_id, 'first_name', sanitize_text_field($_POST['billing_first_name']) );
    }

}
</code>```

Since our site is based in Germany we use the WooCommerce Germanized plugin with the DOI (double opt-in) functionality. So a user receives an activation mail which they have to click in order to active the account. Within the activation mail we want to have a more personal feeling, thus include the first name of the user. There we added the original email template from WooCommerce Germanized to our child theme.

The problem is that the only value I can access (is displayed in the actually delivered email) is $user_login which returns the automatically created username. How can I access the first name of the user which is saved as first name and billing first name. The template within our child theme looks like this:

```<code><?php
/**
 * Customer new account activation email.
 *
 * @see https://github.com/vendidero/woocommerce-germanized/wiki/Overriding-Germanized-Templates
 * @package Germanized/Templates
 * @version 1.6.4
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

?>

<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

    <p><?php printf( __( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ); ?></p>

    <p><?php printf( __( "Thanks for creating an account on %s. Please follow the activation link to activate your account:", 'woocommerce-germanized' ), esc_html( $blogname ) ); ?></p>

    <p><a class="wc-button button"
          href="<?php echo esc_url( $user_activation_url ); ?>"><?php _e( 'Activate your account', 'woocommerce-germanized' ); ?></a>
    </p>

<?php if ( get_option( 'woocommerce_registration_generate_password' ) == 'yes' && $password_generated ) : ?>

    <p><?php printf( __( "Your password has been automatically generated: <strong>%s</strong>", 'woocommerce-germanized' ), esc_html( $user_pass ) ); ?></p>

<?php endif; ?>

    <p style="font-size:75%;"><?php printf( __( "If you haven't created an account on %s please ignore this email.", "woocommerce-germanized" ), esc_html( $blogname ) ); ?></p>

    <p style="font-size:75%;"><?php printf( __( 'If you cannot follow the link above please copy this url and paste it to your browser bar: %s', 'woocommerce-germanized' ), esc_url( $user_activation_url ) ); ?></p>

<?php
/**
 * Show user-defined additional content - this is set in each email's settings.
 */
if ( $additional_content ) {
    echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
?>

<?php do_action( 'woocommerce_email_footer', $email ); ?>
</code>```

I already tried to populate the first name as described here (https://wordpress.org/support/topic/new-account-email-insert-first-name/) and to access it via $user->display_name but this did not work.

I also tried the solution provided here (Get user meta data from woocommerce_created_customer hook in Woocommerce) to access first name via Customer object. The code would then look like below. I didn't work either.

```<code><p><?php $customer = new WC_Customer( $customer_id ); printf( __( 'Hi %s,', 'woocommerce' ), esc_html( $customer->get_first_name() ) ); ?></p>
</code>```

Any help would be highly appreciated!

答:
get the user information by login

$customer = get_user_by('login', $user_login);

and get the name using the user id

$firstName = get_user_meta($customer->ID,'billing_first_name',true);

if the user is not registered, so, you can use this

esc_html( $firstName ) );

instead to

esc_html( $customer->get_first_name() ) );

Body:
We have a custom registration page for our WooCommerce site which is based on a Business Bloomer shortcode and added an input field for the first name of the user. The code within our functions.php looks like this:

/**
 * @snippet       WooCommerce User Registration Shortcode
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.5
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

// THIS WILL CREATE A NEW SHORTCODE: [wc_reg_form_bbloomer]
add_shortcode('wc_reg_form_bbloomer', 'bbloomer_separate_registration_form');

function bbloomer_separate_registration_form()
{
    if (is_admin()) return;
    if (is_user_logged_in()) return;
    ob_start();

    // NOTE: THE FOLLOWING <FORM></FORM> IS COPIED FROM woocommerce\templates\myaccount\form-login.php
    // IF WOOCOMMERCE RELEASES AN UPDATE TO THAT TEMPLATE, YOU MUST CHANGE THIS ACCORDINGLY

?>

      <form method="post" class="woocommerce-form woocommerce-form-register register" <?php do_action('woocommerce_register_form_tag'); ?> >

            <?php do_action('woocommerce_register_form_start'); ?>

            <?php if ('no' === get_option('woocommerce_registration_generate_username')): ?>

                    <?php esc_html_e('Username', 'woocommerce'); ?> *
                    <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="reg_username" autocomplete="username" value="<?php echo (!empty($_POST['username'])) ? esc_attr(wp_unslash($_POST['username'])) : ''; ?>" /><?php // @codingStandardsIgnoreLine
         ?>

            <?php
    endif; ?>

                <?php esc_html_e('Email address', 'woocommerce'); ?> *
                <input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" autocomplete="email" value="<?php echo (!empty($_POST['email'])) ? esc_attr(wp_unslash($_POST['email'])) : ''; ?>" /><?php // @codingStandardsIgnoreLine
     ?>

            <?php if ('no' === get_option('woocommerce_registration_generate_password')): ?>

                    <?php esc_html_e('Password', 'woocommerce'); ?> *
                    <input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password" autocomplete="new-password" />

            <?php
    else: ?>

<?php esc_html_e('A password will be sent to your email address.', 'woocommerce'); ?>

            <?php
    endif; ?>

            <?php do_action('woocommerce_register_form'); ?>

                <?php wp_nonce_field('woocommerce-register', 'woocommerce-register-nonce'); ?>
                <button type="submit" class="woocommerce-Button woocommerce-button button woocommerce-form-register__submit" name="register" value="<?php esc_attr_e('Register', 'woocommerce'); ?>"><?php esc_html_e('Register', 'woocommerce'); ?></button>

            <?php do_action('woocommerce_register_form_end'); ?>

        </form>

   <?php
    return ob_get_clean();
}

/**
 * @snippet       Add First to Register Form - WooCommerce
 * @sourcecode    https://businessbloomer.com/?p=21974
 * @author        Rodolfo Melogli
 * @credits       Claudio SM Web
 * @compatible    WC 3.5.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

///////////////////////////////
// 1. ADD FIELDS

add_action( 'woocommerce_register_form_start', 'bbloomer_add_name_woo_account_registration' );

function bbloomer_add_name_woo_account_registration() {
    ?>

    <?php _e( 'First name', 'woocommerce' ); ?> *
    <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />

    <?php
}

///////////////////////////////
// 2. VALIDATE FIELDS

add_filter( 'woocommerce_registration_errors', 'bbloomer_validate_name_fields', 10, 3 );

function bbloomer_validate_name_fields( $errors, $username, $email ) {
    if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
        $errors->add( 'billing_first_name_error', __( 'Achtung: Vorname ist ein Pflichtfeld!', 'woocommerce' ) );
    }
    return $errors;
}

///////////////////////////////
// 3. SAVE FIELDS

add_action( 'woocommerce_created_customer', 'bbloomer_save_name_fields' );

function bbloomer_save_name_fields( $customer_id ) {
    if ( isset( $_POST['billing_first_name'] ) ) {
        update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
        update_user_meta( $customer_id, 'first_name', sanitize_text_field($_POST['billing_first_name']) );
    }

}

Since our site is based in Germany we use the WooCommerce Germanized plugin with the DOI (double opt-in) functionality. So a user receives an activation mail which they have to click in order to active the account. Within the activation mail we want to have a more personal feeling, thus include the first name of the user. There we added the original email template from WooCommerce Germanized to our child theme.

The problem is that the only value I can access (is displayed in the actually delivered email) is $user_login which returns the automatically created username. How can I access the first name of the user which is saved as first name and billing first name. The template within our child theme looks like this:

<?php
/**
 * Customer new account activation email.
 *
 * @see https://github.com/vendidero/woocommerce-germanized/wiki/Overriding-Germanized-Templates
 * @package Germanized/Templates
 * @version 1.6.4
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

?>

<?php do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

<?php printf( __( 'Hi %s,', 'woocommerce' ), esc_html( $user_login ) ); ?>

<?php printf( __( "Thanks for creating an account on %s. Please follow the activation link to activate your account:", 'woocommerce-germanized' ), esc_html( $blogname ) ); ?>

<a class="wc-button button"
          href="<?php echo esc_url( $user_activation_url ); ?>"><?php _e( 'Activate your account', 'woocommerce-germanized' ); ?>

<?php if ( get_option( 'woocommerce_registration_generate_password' ) == 'yes' && $password_generated ) : ?>

<?php printf( __( "Your password has been automatically generated: %s", 'woocommerce-germanized' ), esc_html( $user_pass ) ); ?>

<?php endif; ?>

<?php printf( __( "If you haven't created an account on %s please ignore this email.", "woocommerce-germanized" ), esc_html( $blogname ) ); ?>

<?php printf( __( 'If you cannot follow the link above please copy this url and paste it to your browser bar: %s', 'woocommerce-germanized' ), esc_url( $user_activation_url ) ); ?>

<?php
/**
 * Show user-defined additional content - this is set in each email's settings.
 */
if ( $additional_content ) {
    echo wp_kses_post( wpautop( wptexturize( $additional_content ) ) );
}
?>

<?php do_action( 'woocommerce_email_footer', $email ); ?>

I already tried to populate the first name as described here (https://wordpress.org/support/topic/new-account-email-insert-first-name/) and to access it via $user->display_name but this did not work.

I also tried the solution provided here (Get user meta data from woocommerce_created_customer hook in Woocommerce) to access first name via Customer object. The code would then look like below. I didn't work either.

<?php $customer = new WC_Customer( $customer_id ); printf( __( 'Hi %s,', 'woocommerce' ), esc_html( $customer->get_first_name() ) ); ?>

Any help would be highly appreciated!


问:
Apache POI - CellDataFormat Exception
I'm trying to create an excel file(.xlsx) and fill it with data using Apache POI, and formatting some cells to an Accounting format, using:

```<code>    CellStyle CellAccounting = spreadsheet.getWorkbook().createCellStyle();
    CreationHelper ch = workbook.getCreationHelper();
    CellAccounting.setDataFormat(ch.createDataFormat().getFormat("_ [$€-nl-NL] * #,##0.00_ ;_ [$€-nl-NL] * -#,##0.00_ ;_ [$€-nl-NL] * \"-\"??_ ;_ @_ "));
</code>```

It keeps throwing IllegalArgumentExceptions, stating that the format is invalid:

```<code>Feb 18, 2020 1:40:10 AM org.apache.poi.ss.format.CellFormat <init>
WARNING: Invalid format: "_ [$€-nl-NL] * "-"??_ ;"
java.lang.IllegalArgumentException: Unsupported [] format block '[' in '_ [$€-nl-NL] * "-"??_' with c2: null
    at org.apache.poi.ss.format.CellFormatPart.formatType(CellFormatPart.java:373)
    at org.apache.poi.ss.format.CellFormatPart.getCellFormatType(CellFormatPart.java:287)
    at org.apache.poi.ss.format.CellFormatPart.<init>(CellFormatPart.java:191)
    at org.apache.poi.ss.format.CellFormat.<init>(CellFormat.java:189)
    at org.apache.poi.ss.format.CellFormat.getInstance(CellFormat.java:163)
    at org.apache.poi.ss.usermodel.DataFormatter.getFormat(DataFormatter.java:343)
    at org.apache.poi.ss.usermodel.DataFormatter.getFormat(DataFormatter.java:309)
    at org.apache.poi.ss.usermodel.DataFormatter.getFormattedNumberString(DataFormatter.java:868)
    at org.apache.poi.ss.usermodel.DataFormatter.formatCellValue(DataFormatter.java:1021)
    at org.apache.poi.ss.usermodel.DataFormatter.formatCellValue(DataFormatter.java:971)
    at org.apache.poi.ss.util.SheetUtil.getCellWidth(SheetUtil.java:170)
    at org.apache.poi.ss.util.SheetUtil.getColumnWidthForRow(SheetUtil.java:300)
    at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:254)
    at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:233)
    at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:555)
    at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:537)
    at MyClass.createExcel(MyClass.java:325)
    at MyClass.saveFile(MyClass.java:82)
    at ClickListener.actionPerformed(ClickListener.java:95)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6401)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

</code>```

However, my data is exporting fine to excell, everything is working as intended. The format is working perfectly (in Excel, in a file created and modified through Java, using this format).

Interestingly, the point at which the exception is thrown, MyClass line 325 is simply:

```<code>            spreadsheet.autoSizeColumn(1);
</code>```

So maybe the error has nothing to do with writing the data, but it's just the resizing that isn't going over smoothly? I'm not well versed in excel, so I don't know how this data formatting works in excel on a programming level.

Could anyone help me resolve this, if there is a need for that at all? Maybe POI just isn't able to recognize such a (foreign language) format?

Cheers,

答:
Excel itself is not using language tags like nl-NL in number formats. Instead it uses the Windows Language Code Identifier (LCID). This is 413 for nl-NL.

The Sheet.autoSizeColumn needs to know the number format to calculate the needed column widths. So it tries to parse your number format having [$€-nl-NL] in it and fails. Using [$€-413], which is the same, it will be successful.

The following works for me:

```<code>import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

class CreateExcelCellAccountingStyle {

 public static void main(String[] args) throws Exception {

  try (Workbook workbook = new XSSFWorkbook();
       FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {

   Object[][] data = new Object[][] {
    new Object[] {"Text", "Value"},
    new Object[] {"Value 1", 123.456789},
    new Object[] {"Value 2", 1234.56789}
   };

   DataFormat dataFormat = workbook.createDataFormat();
   CellStyle cellAccountingStyle = workbook.createCellStyle();
   //cellAccountingStyle.setDataFormat(dataFormat.getFormat("_ [$€-nl-NL] * #,##0.00_ ;_ [$€-nl-NL] * -#,##0.00_ ;_ [$€-nl-NL] * \"-\"??_ ;_ @_ "));
   cellAccountingStyle.setDataFormat(dataFormat.getFormat("_ [$€-413] * #,##0.00_ ;_ [$€-413] * -#,##0.00_ ;_ [$€-413] * \"-\"??_ ;_ @_ "));

   Sheet sheet = workbook.createSheet();

   for (int r = 0; r < data.length; r++) {
    Row row = sheet.createRow(r);
    for (int c = 0; c < data[0].length; c++) {
     Cell cell = row.createCell(c);
     if (data[r][c] instanceof String) {
      cell.setCellValue((String)data[r][c]);
     } else if (data[r][c] instanceof Double) {
      cell.setCellValue((Double)data[r][c]);
      cell.setCellStyle(cellAccountingStyle);
     }
    }
   }

   for (int c = 0; c < data[0].length; c++) {
    sheet.autoSizeColumn(c);
   }

   workbook.write(fileout);
  }

 }
}
</code>```

Title: Apache POI - CellDataFormat Exception

Body:
I'm trying to create an excel file(.xlsx) and fill it with data using Apache POI, and formatting some cells to an Accounting format, using:

    CellStyle CellAccounting = spreadsheet.getWorkbook().createCellStyle();
    CreationHelper ch = workbook.getCreationHelper();
    CellAccounting.setDataFormat(ch.createDataFormat().getFormat("_ [$€-nl-NL] * #,##0.00_ ;_ [$€-nl-NL] * -#,##0.00_ ;_ [$€-nl-NL] * \"-\"??_ ;_ @_ "));

It keeps throwing IllegalArgumentExceptions, stating that the format is invalid:

Feb 18, 2020 1:40:10 AM org.apache.poi.ss.format.CellFormat <init>
WARNING: Invalid format: "_ [$€-nl-NL] * "-"??_ ;"
java.lang.IllegalArgumentException: Unsupported [] format block '[' in '_ [$€-nl-NL] * "-"??_' with c2: null
    at org.apache.poi.ss.format.CellFormatPart.formatType(CellFormatPart.java:373)
    at org.apache.poi.ss.format.CellFormatPart.getCellFormatType(CellFormatPart.java:287)
    at org.apache.poi.ss.format.CellFormatPart.<init>(CellFormatPart.java:191)
    at org.apache.poi.ss.format.CellFormat.<init>(CellFormat.java:189)
    at org.apache.poi.ss.format.CellFormat.getInstance(CellFormat.java:163)
    at org.apache.poi.ss.usermodel.DataFormatter.getFormat(DataFormatter.java:343)
    at org.apache.poi.ss.usermodel.DataFormatter.getFormat(DataFormatter.java:309)
    at org.apache.poi.ss.usermodel.DataFormatter.getFormattedNumberString(DataFormatter.java:868)
    at org.apache.poi.ss.usermodel.DataFormatter.formatCellValue(DataFormatter.java:1021)
    at org.apache.poi.ss.usermodel.DataFormatter.formatCellValue(DataFormatter.java:971)
    at org.apache.poi.ss.util.SheetUtil.getCellWidth(SheetUtil.java:170)
    at org.apache.poi.ss.util.SheetUtil.getColumnWidthForRow(SheetUtil.java:300)
    at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:254)
    at org.apache.poi.ss.util.SheetUtil.getColumnWidth(SheetUtil.java:233)
    at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:555)
    at org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:537)
    at MyClass.createExcel(MyClass.java:325)
    at MyClass.saveFile(MyClass.java:82)
    at ClickListener.actionPerformed(ClickListener.java:95)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6401)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

However, my data is exporting fine to excell, everything is working as intended. The format is working perfectly (in Excel, in a file created and modified through Java, using this format).

Interestingly, the point at which the exception is thrown, MyClass line 325 is simply:

            spreadsheet.autoSizeColumn(1);

So maybe the error has nothing to do with writing the data, but it's just the resizing that isn't going over smoothly? I'm not well versed in excel, so I don't know how this data formatting works in excel on a programming level.

Could anyone help me resolve this, if there is a need for that at all? Maybe POI just isn't able to recognize such a (foreign language) format?

Cheers,

Body:
Excel itself is not using language tags like nl-NL in number formats. Instead it uses the Windows Language Code Identifier (LCID). This is 413 for nl-NL.

The Sheet.autoSizeColumn needs to know the number format to calculate the needed column widths. So it tries to parse your number format having [$€-nl-NL] in it and fails. Using [$€-413], which is the same, it will be successful.

The following works for me:

import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

class CreateExcelCellAccountingStyle {

 public static void main(String[] args) throws Exception {

  try (Workbook workbook = new XSSFWorkbook();
       FileOutputStream fileout = new FileOutputStream("Excel.xlsx") ) {

   Object[][] data = new Object[][] {
    new Object[] {"Text", "Value"},
    new Object[] {"Value 1", 123.456789},
    new Object[] {"Value 2", 1234.56789}
   };

   DataFormat dataFormat = workbook.createDataFormat();
   CellStyle cellAccountingStyle = workbook.createCellStyle();
   //cellAccountingStyle.setDataFormat(dataFormat.getFormat("_ [$€-nl-NL] * #,##0.00_ ;_ [$€-nl-NL] * -#,##0.00_ ;_ [$€-nl-NL] * \"-\"??_ ;_ @_ "));
   cellAccountingStyle.setDataFormat(dataFormat.getFormat("_ [$€-413] * #,##0.00_ ;_ [$€-413] * -#,##0.00_ ;_ [$€-413] * \"-\"??_ ;_ @_ "));

   Sheet sheet = workbook.createSheet();

   for (int r = 0; r < data.length; r++) {
    Row row = sheet.createRow(r);
    for (int c = 0; c < data[0].length; c++) {
     Cell cell = row.createCell(c);
     if (data[r][c] instanceof String) {
      cell.setCellValue((String)data[r][c]);
     } else if (data[r][c] instanceof Double) {
      cell.setCellValue((Double)data[r][c]);
      cell.setCellStyle(cellAccountingStyle);
     }
    }
   }

   for (int c = 0; c < data[0].length; c++) {
    sheet.autoSizeColumn(c);
   }

   workbook.write(fileout);
  }

 }
}


问:
Electron block using shortcut CTRL + minus button
I need block in my app in Electron shortcut CTRL + -.
I write in main.js:

```<code>globalShortcut.register("CmdOrCtrl+-", () => false);
</code>```

But it's not working.

If I have e.g.:

```<code>globalShortcut.register("CmdOrCtrl+R", () => false);
</code>```

then shortcut CTRL + R is blocked correctly.

答:
You have to use numsub instead of '-' directly.

like globalShortcut.register("CmdOrCtrl+numsub", () => false);

ref : https://www.electronjs.org/docs/api/accelerator

Body:
I need block in my app in Electron shortcut CTRL + -.
I write in main.js:

globalShortcut.register("CmdOrCtrl+-", () => false);

But it's not working.

If I have e.g.:

globalShortcut.register("CmdOrCtrl+R", () => false);

then shortcut CTRL + R is blocked correctly.


问:
SQL limiting the output to a number of results
I have this query.

SELECT * FROM Customer WHERE TAGID IN ('UK', 'Germany');

This outputs the results to show all customers in UK and Germany, but as you can imagine, there will be loads of outputs, and I just require it to output 2 results for UK and 2 results for Germany?

Is this possible?

答:
Yes It is possible. Please check below methods.

Method 1 :

```<code>SELECT TOP 2 * FROM Customer WHERE TAGID ='UK'
UNION ALL
SELECT TOP 2 * FROM Customer WHERE TAGID = 'Germany'
</code>```

Method 2:

```<code>(SELECT * FROM Customer WHERE TAGID ='UK' LIMIT 2)
UNION ALL
(SELECT * FROM Customer WHERE TAGID = 'Germany' LIMIT 2)
</code>```

Method 3:

```<code>(SELECT * FROM Customer WHERE TAGID ='UK' AND ROWNUM = 2)
UNION ALL
(SELECT * FROM Customer WHERE TAGID = 'Germany' AND ROWNUM = 2)
</code>```

Body:
Yes It is possible. Please check below methods.

Method 1 :

SELECT TOP 2 * FROM Customer WHERE TAGID ='UK'
UNION ALL
SELECT TOP 2 * FROM Customer WHERE TAGID = 'Germany'

Method 2:

(SELECT * FROM Customer WHERE TAGID ='UK' LIMIT 2)
UNION ALL
(SELECT * FROM Customer WHERE TAGID = 'Germany' LIMIT 2)

Method 3:

(SELECT * FROM Customer WHERE TAGID ='UK' AND ROWNUM = 2)
UNION ALL
(SELECT * FROM Customer WHERE TAGID = 'Germany' AND ROWNUM = 2)


问:
TypeError: Object prototype may only be an Object or null: undefined Angular 8
Whenever I try to start up my web app, I get this Type error. Can't figure out why.

I started to get it after I updated some packages. I can't figure out which one was the problem or why the code that the error points to give wrong as it is code in my dependencies for Angular 8. I am not really sure what the error is even telling me.
I have tried to update all dependencies. I have looked at almost all the similar question solutions and they have not worked. I can't tell if it is a compiler error, typescript, or a dependency error.

ERROR

```<code>[error] TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at Object.__extends (C:\Users\leahb\Desktop\NH\NH-Senior-Project\node_modules\tslib\tslib.js:65:9)
    at C:\Users\leahb\Desktop\NH\NH-Senior-Project\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:115:17

tslib.js at line 65
    (function (exporter) {
        var extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };

        __extends = function (d, b) {
            extendStatics(d, b); *//saying the error is coming from here*
            function __() { this.constructor = d; }
            d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
        };

</code>```

PACKAGE.JSON

```<code>{
  "name": "nh",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "heroku-postbuild": "ng build --prod"
  },
  "keywords": [
    "heroku"
  ],
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.6",
    "@angular-devkit/build-angular": "^0.13.0",
    "@angular/animations": "~8.1.2",
    "@angular/common": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@types/googlemaps": "^3.37.0",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "ngx-gallery": "^5.10.0",
    "rxjs": "~6.5.2",
    "tslib": "^1.9.0",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular/cli": "^7.3.9",
    "@angular/compiler": "^7.2.15",
    "@angular/compiler-cli": "^8.1.2",
    "@angular/language-service": "~8.1.2",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "enhanced-resolve": "^3.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "^3.4.5"
  },
  "engines": {
    "node": "10.16.0",
    "npm": "6.9.0"
  }
}
</code>```

I expected the app to compile, build, and start up. Whenever I tried ng serve, ng test, or ng build I get this error.

答: In my Ionic App i downgraded the Angular CLI from 8.x.x to 5.2.11 using npm i @angular/compiler-cli@5.2.11 and it worked

Body:
Whenever I try to start up my web app, I get this Type error. Can't figure out why.

I started to get it after I updated some packages. I can't figure out which one was the problem or why the code that the error points to give wrong as it is code in my dependencies for Angular 8. I am not really sure what the error is even telling me.
I have tried to update all dependencies. I have looked at almost all the similar question solutions and they have not worked. I can't tell if it is a compiler error, typescript, or a dependency error.

ERROR

[error] TypeError: Object prototype may only be an Object or null: undefined
    at setPrototypeOf (<anonymous>)
    at Object.__extends (C:\Users\leahb\Desktop\NH\NH-Senior-Project\node_modules\tslib\tslib.js:65:9)
    at C:\Users\leahb\Desktop\NH\NH-Senior-Project\node_modules\@angular\compiler-cli\src\ngtsc\indexer\src\template.js:115:17

tslib.js at line 65
    (function (exporter) {
        var extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };

        __extends = function (d, b) {
            extendStatics(d, b); *//saying the error is coming from here*
            function __() { this.constructor = d; }
            d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
        };

PACKAGE.JSON

{
  "name": "nh",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "heroku-postbuild": "ng build --prod"
  },
  "keywords": [
    "heroku"
  ],
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.6",
    "@angular-devkit/build-angular": "^0.13.0",
    "@angular/animations": "~8.1.2",
    "@angular/common": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@types/googlemaps": "^3.37.0",
    "core-js": "^2.5.4",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "ngx-gallery": "^5.10.0",
    "rxjs": "~6.5.2",
    "tslib": "^1.9.0",
    "zone.js": "^0.9.1"
  },
  "devDependencies": {
    "@angular/cli": "^7.3.9",
    "@angular/compiler": "^7.2.15",
    "@angular/compiler-cli": "^8.1.2",
    "@angular/language-service": "~8.1.2",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "enhanced-resolve": "^3.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "^3.4.5"
  },
  "engines": {
    "node": "10.16.0",
    "npm": "6.9.0"
  }
}

I expected the app to compile, build, and start up. Whenever I tried ng serve, ng test, or ng build I get this error.


问:
Use column if it exists, another if doesn't in SQL Server
I have a number of SQL Server databases (different versions from 2012 to 2019). The schema in each one is very similar but not exactly the same.  For example, there's table ORDERS, which has about 50 columns - and one column is called differently in two different databases:

in DB1: select p_user from orders

in DB2: select userpk from orders

Note that I showed two databases above, but there are actually more than 20 - some are DB1 type, the others are DB2 type

I can't do much about these differences - they are historic - and changing the schema to match is not an option.

I want to be able to run the same SQL statement against all of these databases at once.  I'd like to write the query in such a way that it would use one column if it exists and another if it doesn't.  For example:

```<code>select
    case
        when COL_LENGTH('orders', 'p_user') IS NOT NULL
    then
        orders.p_user
    else
        orders.userpk
    end
from orders
</code>```

This unfortunately doesn't work, as SQL server seems to try to evaluate both results regardless of whether the condition is true or false.  The same thing happens if I use IIF function.

If I simply run

```<code>select
    case
        when COL_LENGTH('orders', 'p_user') IS NOT NULL
    then
        'orders.p_user'
    else
        'orders.userpk'
    end
</code>```

then I do get the correct string, which means my condition is correct.

How can I formulate the SQL statement to use one or the other column based on whether the first one exists?

答:
Fix your tables by adding a computed column:

```<code>alter table db1..orders
    add statuspk as (p_status);
</code>```

(Or choose the other name.)

Then, your queries will just work without adding unnecessary complication to queries.

Body:
I have a number of SQL Server databases (different versions from 2012 to 2019). The schema in each one is very similar but not exactly the same.  For example, there's table ORDERS, which has about 50 columns - and one column is called differently in two different databases:

in DB1: select p_user from orders

in DB2: select userpk from orders

Note that I showed two databases above, but there are actually more than 20 - some are DB1 type, the others are DB2 type

I can't do much about these differences - they are historic - and changing the schema to match is not an option.

I want to be able to run the same SQL statement against all of these databases at once.  I'd like to write the query in such a way that it would use one column if it exists and another if it doesn't.  For example:

select
    case
        when COL_LENGTH('orders', 'p_user') IS NOT NULL
    then
        orders.p_user
    else
        orders.userpk
    end
from orders

This unfortunately doesn't work, as SQL server seems to try to evaluate both results regardless of whether the condition is true or false.  The same thing happens if I use IIF function.

If I simply run

select
    case
        when COL_LENGTH('orders', 'p_user') IS NOT NULL
    then
        'orders.p_user'
    else
        'orders.userpk'
    end

then I do get the correct string, which means my condition is correct.

How can I formulate the SQL statement to use one or the other column based on whether the first one exists?

Body:
Fix your tables by adding a computed column:

alter table db1..orders
    add statuspk as (p_status);

(Or choose the other name.)

Then, your queries will just work without adding unnecessary complication to queries.


问:
Htaccess - multiple rules in one file
I am trying to do two things with my .htaccess file.

To redirect to HTTPS (SSL) server

To configure my custom error 404 page

This is what I have got thus far:

```<code>RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://www.example.co.uk/$1 [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.html
ErrorDocument 404 /404.html
</code>```

Is it ok to have RewriteEngine On in there twice?

Please note that the latter part of the script was obtained from the following article, as I use their webhosting servers:
https://www.ionos.co.uk/help/hosting/html-and-css/create-your-own-error-pages-linux-webhosting

答:
Is it ok to have RewriteEngine On in there twice?

It's "OK", but you don't need it and you are better off only including it once at the top of your file.

If you have multiple RewriteEngine directives then the last one wins and controls the entire scope/file. eg. If you included RewriteEngine Off at the very end of the file then it would disable the rewrite engine for the entire file, despite the preceding RewriteEngine On directives.

```<code>RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://www.[MY URL].co.uk/$1 [R=301,L]
</code>```

That's OK as an HTTP to HTTPS redirect, providing the SSL cert is installed directly on the application server. Bear in mind that server configs vary, and hence might have different requirements with regards to the HTTP to HTTPS redirect (which part explains why there is a variation of directives you see on the internet). And there is also several ways of doing the same thing.

```<code>RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.html
ErrorDocument 404 /404.html
</code>```

You are "kind of" doing the same thing here with mod_rewrite (RewriteCond and RewriteRule) and the ErrorDocument directive. You should define your custom error document with the ErrorDocument directive, not mod_rewrite.

The mod_rewrite directives internally rewrite the request to /404.html after performing a couple of filesystem checks (that the request does not map to a directory or file).

The ErrorDocument directive tells Apache to serve that document (via an internal subrequest) when it would otherwise trigger a 404.

The mod_rewrite directives would override the ErrorDocument, since they are processed earlier in the request (although this has nothing to do with the order of the directives in the file).

```<code>RewriteBase /
</code>```

This directive is not being used here and can be deleted. The RewriteBase directive (part of mod_rewrite) sets the directory-prefix to use for relative path substitutions. You don't currently have any relative path substitutions in your config file.

So, in other words, your file should be written like this:

```<code>RewriteEngine On

ErrorDocument 404 /404.html

# HTTP to HTTPS redirect
RewriteCond %{SERVER_PORT} !=443
RewriteRule (.*) https://www.example.co.uk/$1 [R=301,L]
</code>```

The order of these directives does not strictly matter, although it is more logical to define your custom error documents near the top of the file.

Please note that the latter part of the script was obtained from the following article

Well, that article is "wrong". It won't cause an "error", but it could produce undesirable results further down the line. At best, it's simply misleading and "bloated". (For instance... why are they capturing a backreference in the RewriteRule pattern? Why no L flag? And, as mentioned, why are they setting RewriteBase? etc.)

Unfortunately, with regards to .htaccess (and especially mod_rewrite) there is a lot of missinformation out there!

Title: Htaccess - multiple rules in one file

Body:
I am trying to do two things with my .htaccess file.

To redirect to HTTPS (SSL) server

To configure my custom error 404 page

This is what I have got thus far:

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://www.example.co.uk/$1 [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.html
ErrorDocument 404 /404.html

Is it ok to have RewriteEngine On in there twice?

Please note that the latter part of the script was obtained from the following article, as I use their webhosting servers:
https://www.ionos.co.uk/help/hosting/html-and-css/create-your-own-error-pages-linux-webhosting

Body:
Is it ok to have RewriteEngine On in there twice?

It's "OK", but you don't need it and you are better off only including it once at the top of your file.

If you have multiple RewriteEngine directives then the last one wins and controls the entire scope/file. eg. If you included RewriteEngine Off at the very end of the file then it would disable the rewrite engine for the entire file, despite the preceding RewriteEngine On directives.

RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://www.[MY URL].co.uk/$1 [R=301,L]

That's OK as an HTTP to HTTPS redirect, providing the SSL cert is installed directly on the application server. Bear in mind that server configs vary, and hence might have different requirements with regards to the HTTP to HTTPS redirect (which part explains why there is a variation of directives you see on the internet). And there is also several ways of doing the same thing.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /404.html
ErrorDocument 404 /404.html

You are "kind of" doing the same thing here with mod_rewrite (RewriteCond and RewriteRule) and the ErrorDocument directive. You should define your custom error document with the ErrorDocument directive, not mod_rewrite.

The mod_rewrite directives internally rewrite the request to /404.html after performing a couple of filesystem checks (that the request does not map to a directory or file).

The ErrorDocument directive tells Apache to serve that document (via an internal subrequest) when it would otherwise trigger a 404.

The mod_rewrite directives would override the ErrorDocument, since they are processed earlier in the request (although this has nothing to do with the order of the directives in the file).

RewriteBase /

This directive is not being used here and can be deleted. The RewriteBase directive (part of mod_rewrite) sets the directory-prefix to use for relative path substitutions. You don't currently have any relative path substitutions in your config file.

So, in other words, your file should be written like this:

RewriteEngine On

ErrorDocument 404 /404.html

# HTTP to HTTPS redirect
RewriteCond %{SERVER_PORT} !=443
RewriteRule (.*) https://www.example.co.uk/$1 [R=301,L]

The order of these directives does not strictly matter, although it is more logical to define your custom error documents near the top of the file.

Please note that the latter part of the script was obtained from the following article

Well, that article is "wrong". It won't cause an "error", but it could produce undesirable results further down the line. At best, it's simply misleading and "bloated". (For instance... why are they capturing a backreference in the RewriteRule pattern? Why no L flag? And, as mentioned, why are they setting RewriteBase? etc.)

Unfortunately, with regards to .htaccess (and especially mod_rewrite) there is a lot of missinformation out there!


问:
AWS sdk for android: How to change the host end point
I'm using Wasabi for my file storage and I need to change the AWS SDK clients host url to that of wasabi. How can I do that?

```<code>AmazonS3Client s3client = new AmazonS3Client(new AWSCredentials() {
        @Override
        public String getAWSAccessKeyId() {
            return accessKey;
        }
        @Override
        public String getAWSSecretKey() {
           return secretKey;
        }
});

/// Tried this but its not changing the endpoint and its still showing as aws s3 default endpoint.
s3client.setEndpoint(String.format("https://s3.wasabisys.com", Regions.US_EAST_1));
s3client.setRegion(Region.getRegion(Regions.US_EAST_1));

File fileToUpload = new File(filePath);
PutObjectRequest putRequest = new PutObjectRequest("ALPHA", "upload/" +
fileToUpload.getName(), fileToUpload);

PutObjectResult putResponse = s3client.putObject(putRequest);
putResponse.getContentMd5();
</code>```

答:
You can override the credentials like this,</p>

```<code>    AWSCredentials myCredentials = new BasicAWSCredentials(
            "AWS_ACCESS_KEY_ID", "AWS_SECRET_KEY_ID");
    AmazonS3 s3client = new AmazonS3Client(myCredentials,
    Region.getRegion(Regions.AP_EAST_1));
    s3client.setEndpoint("ENDPOINT_S3");
</code>```

Body:
I'm using Wasabi for my file storage and I need to change the AWS SDK clients host url to that of wasabi. How can I do that?

AmazonS3Client s3client = new AmazonS3Client(new AWSCredentials() {
        @Override
        public String getAWSAccessKeyId() {
            return accessKey;
        }
        @Override
        public String getAWSSecretKey() {
           return secretKey;
        }
});

/// Tried this but its not changing the endpoint and its still showing as aws s3 default endpoint.
s3client.setEndpoint(String.format("https://s3.wasabisys.com", Regions.US_EAST_1));
s3client.setRegion(Region.getRegion(Regions.US_EAST_1));

File fileToUpload = new File(filePath);
PutObjectRequest putRequest = new PutObjectRequest("ALPHA", "upload/" +
fileToUpload.getName(), fileToUpload);

PutObjectResult putResponse = s3client.putObject(putRequest);
putResponse.getContentMd5();

Body:
You can override the credentials like this,

    AWSCredentials myCredentials = new BasicAWSCredentials(
            "AWS_ACCESS_KEY_ID", "AWS_SECRET_KEY_ID");
    AmazonS3 s3client = new AmazonS3Client(myCredentials,
    Region.getRegion(Regions.AP_EAST_1));
    s3client.setEndpoint("ENDPOINT_S3");


问:
High quality typesetting system
I'm looking for a high quality typesetting system to replace TeX.

My problem with TeX is that it's too brittle to deploy for John Doe. I need something that I can package with my Java app, unzip somewhere on the user's computer and be sure that it will work.

If the system is written in Java, that would be great but I'm collecting options right now.

答:
After some searching, I found these resources:

New Typesetting System (NTS): "The New Typesetting System (NTS) is a reimplementation of the typesetting system TeX in Java". Unfortunately, the project is dead and the website is down. From the Wikipedia article:

First of all, NTS is too slow to be used for production purposes, which does not motivate users to switch to this engine. Furthermore, the by-then standard extensions such as e-TeX were not included in the code. Also, in order to be useful today, PDF output as well as pdfTeX-specific extensions need to be implemented. Finally, by being 100%-compatible with TeX, the sub-processes of NTS are rather interwoven (due to the nature of traditional TeX), which thereby makes the task of adding extensions less simple than had been envisaged.

The ExTeX project took over. It's basically a reimplementation of TeX in Java and tries to improve TeX instead of creating a 1:1 clone in Java.

That means you get the layout engine plus a TeX parser but you can use either or both as you need.

Lastly, there is the luaTeX project but it's a 1:1 clone, so it suffers from most of the shortcomings as TeX. Unlike ExTeX, they try to improve the situation in small steps, for example by allowing to write macros in lua.

Title: High quality typesetting system