簡體   English   中英

Windows Phone:表情符號網格

[英]Windows Phone: Emoticons Grid

如何在Windows Phone中創建表情符號網格? 我是Windows Phone的新手,我不知道如何實現此功能以及要使用哪個控件...我在google上搜索但未獲得適當的解決方案。我嘗試使用網格控件,但無法正常工作。 在此處輸入圖片說明

我已經為此創建了一個自定義控件,如下所示:

<Controls:ChildWindow x:Class="ChildWindows.SmileyDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=CustomControls"
    xmlns:Toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    BorderThickness="2" mc:Ignorable="d"
    BorderBrush="{StaticResource PhoneBorderBrush}"
    Style="{StaticResource ChildWindowTemplate}" >

    <Grid x:Name="LayoutRoot" HorizontalAlignment="Center" VerticalAlignment="Center" Background="{ StaticResource PhoneBackgroundBrush }" >
        <ListBox x:Name="itemControl" Margin="4" ItemsSource="{Binding}" Background="White">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <Toolkit:WrapPanel HorizontalAlignment="Center"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border Margin="10" BorderThickness="1" BorderBrush="Silver">
                        <Image Margin="5" Width="64" Height="64" Source="{Binding ImagePaths.Large_69x69}" Toolkit:TiltEffect.IsTiltEnabled="True" />
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Controls:ChildWindow>

該控件背后的代碼:

public partial class SmileyDialog
{
    #region Fields

    public event CloseEventHandler<EmoticonItem> OnClose;

    #endregion Fields

    #region Properties

    public bool IsOpened { get { return ChildWindowPopup.IsOpen; } }

    #endregion Properties

    #region Constructor

    public SmileyDialog()
    {
        InitializeComponent();

        itemControl.ItemsSource = EmoticonsMap.GetEmoticons();
    }

    #endregion Constructor

    #region overrides

    protected override void OnOpened()
    {
        var page = ((ContentControl)Application.Current.RootVisual).Content as PhoneApplicationPage;
        if (page != null) page.BackKeyPress += PageBackKeyPress;

        itemControl.SelectedItem = null;
        itemControl.SelectionChanged += ItemControlSelectionChanged;
    }

    protected override void OnClosing(CancelEventArgs e)
    {
        var page = ((ContentControl)Application.Current.RootVisual).Content as PhoneApplicationPage;
        if (page != null) page.BackKeyPress -= PageBackKeyPress;
        itemControl.SelectionChanged -= ItemControlSelectionChanged;

        if (OnClose != null) OnClose(itemControl.SelectedItem as EmoticonItem);
    }

    #endregion overrides

    #region UI events

    private void PageBackKeyPress(object sender, CancelEventArgs e)
    {
        Close();
    }

    private void ItemControlSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        Close();
    }

    #endregion UI events
}

用法:

private SmileyDialog _smileDialog;

        private void RadSmileyImageButton_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (_smileDialog != null && _smileDialog.IsOpened) return;

            //SetApplicationBarVisibility(false);

            if (_smileDialog == null)
            {
                _smileDialog = new SmileyDialog();
                _smileDialog.OnClose += SmileDialogOnClose;
            }
            _smileDialog.Show();
        }

我希望您能夠重用該代碼,即使沒有對我進行評論也可以。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM