Windows Phone:表情符号网格

时间:2013-11-14 12:39:36

标签: windows-phone-7 windows-phone-8 windows-phone windows-phone-7.1

如何在Windows手机中创建表情符号网格? 我是Windows手机的新手,我不知道如何实现这个和使用哪个控件...我在谷歌搜索但没有得到正确的解决方案。我试图用网格控制,但它没有工作。{{ 0}}

1 个答案:

答案 0 :(得分:1)

我为此创建了一个自定义控件,如下所示:

<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();
        }

我希望你能重复使用这些代码,如果不给我评论帮助的话。