μκ°μ΄ κ½€ νλ μ΅λλ€. μμ¦μλ μΌμ£ΌμΌμ΄ ν루 μ§λκ°λ κ² λ§λ₯ μ§λκ°λ€μ. λ²μ¨ 3μλ λλκ°κ³ μμ΅λλ€.
Unoλ UWPλ₯Ό μ΄λ―Έ ν λΆμ΄λΌλ©΄ κ±°μ μ μ κΈ°κ° μμ΄ κ°λ° μ§νμ΄ κ°λ₯ν©λλ€. Microsoft.UI.Xaml.Controls
μ νΈνλλ XAML λ° μ»¨νΈλ‘€μ κ·Έλλ‘ μ¬μ©ν μ μκΈ° λλ¬Έμ
λλ€. λν WinUI 3μ κ²½ννλ€λ©΄ λ§μ°¬κ°μ§λ‘ λ°λ‘ κ°λ°μ΄ κ°λ₯ν©λλ€.
νλ©΄ λ μ΄μμμ ꡬμ±νμ΅λλ€.
λ©μμ§ λͺ©λ‘μ 1λ§κ°λ‘ λ°μ€ν¬ν± μ± ννλ‘ κ±°μ μ¦μ νμλλ κ²μ μ μ μμκ³ μΉμ΄μ
λΈλ¦¬λ‘λ μλΉν λΉ λ₯΄κ² νμλλ κ²μ νμΈν μ μμμ΅λλ€.
μ€λμ λ©μμ§ μ
λ ₯ μμμ μ‘°λͺ
ν΄λ³΄κ² μ΅λλ€.
μ΄ λΆλΆμΈλ°μ, νΉλ³ν κ²μ μμ§λ§ λμ€μ μν΄ μ»΄ν¬λνΈν νμ΅λλ€.
| MessageInput.xaml
<UserControl
x:Class="DnSE.Controls.MessageInput"
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:local="using:DnSE.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid MinHeight="64" MaxHeight="300">
<ScrollViewer Grid.Column="0">
<TextBox
x:Name="messageTextBox"
AcceptsReturn="True"
Text="{x:Bind Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap">
</TextBox>
</ScrollViewer>
<SplitButton
x:Name="sendButton"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Command="{x:Bind SendCommand}">
<SymbolIcon Symbol="Send" />
</SplitButton>
</Grid>
</UserControl>
| MessageInput.xaml.cs
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Windows.Input;
namespace DnSE.Controls;
public sealed partial class MessageInput : UserControl
{
public static readonly DependencyProperty MessageProperty = DependencyProperty.Register(
nameof(Message),
typeof(string),
typeof(MessageInput),
new PropertyMetadata(string.Empty, OnMessageChanged)
);
public static readonly DependencyProperty SendCommandProperty = DependencyProperty.Register(
nameof(SendCommand),
typeof(ICommand),
typeof(MessageInput),
new PropertyMetadata(null)
);
public string Message
{
get => (string)GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}
public ICommand? SendCommand
{
get => (ICommand)GetValue(SendCommandProperty);
set => SetValue(SendCommandProperty, value);
}
public MessageInput()
{
this.InitializeComponent();
sendButton.IsEnabled = false;
}
private static void OnMessageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = (d as MessageInput)!;
if (string.IsNullOrEmpty(e.NewValue.ToString()) is true)
@this.sendButton.IsEnabled = false;
else
@this.sendButton.IsEnabled = true;
}
}
Message
λ° SendCommand
λ₯Ό λ°μΈλ© ν μ μμ΄μ λ€μκ³Ό κ°μ΄ μ¬μ©ν μ μμ΅λλ€.
| MainPage.xaml
<controls:MessageInput Message="{x:Bind ViewModel.ChatMessage, Mode=TwoWay}" SendCommand="{x:Bind ViewModel.SendCommand}" />
μΌλ°μ μΈ XAMLμ λ°μΈλ©κ³Ό λμΌνμ£ ?