C
C#9mo ago
Mekasu0124

✅ How To Get Notification Of When User Has Scrolled Down To End - Avalonia

<Border>
<Grid RowDefinitions="Auto, *">
<Label Classes="Title" Content="{Binding Title}" Grid.Row="0" />

<ScrollViewer Classes="Tos" AllowAutoHide="True" Grid.Row="1">
<TextBlock Classes="Tos" Text="{Binding TosText}" />
</ScrollViewer>
</Grid>
</Border>
<Border>
<Grid RowDefinitions="Auto, *">
<Label Classes="Title" Content="{Binding Title}" Grid.Row="0" />

<ScrollViewer Classes="Tos" AllowAutoHide="True" Grid.Row="1">
<TextBlock Classes="Tos" Text="{Binding TosText}" />
</ScrollViewer>
</Grid>
</Border>
in my view, I have the above code. It works fine for scrolling down to view the information. I'm going to be putting two buttons on this screen. Accept and Decline. I want to set the Accept button up to where it's disabled until the user has scrolled all the way down on the TextBlock. Does anyone have any ideas on how to do this? Thanks.
4 Replies
Buddy
Buddy9mo ago
Make an attached property Then check the scroll offset when changed, if at bottom then you can call the callback
Mekasu0124
Mekasu0124OP9mo ago
ok ty I looked through the properties of the TextBlock at https://reference.avaloniaui.net/api/Avalonia.Controls/TextBlock/#Properties and I don't see a property that would give me what I'm wanting well the ScrollViewer not the TextBlock. let me go look at that instead
Buddy
Buddy9mo ago
Look up attached properties
Mekasu0124
Mekasu0124OP9mo ago
oh wow. ok. that's a lot small side question. I'm building a ToS screen for my application and it has two buttons. Agree and Decline. They are created like this:
public partial class TosViewModel: ViewModelBase
{
public TosViewModel(...)
{
IObservable<bool> okEnabled = (IObservable<bool>)this.WhenAnyValue(
x => ,
x => );

Agree = ReactiveCommand.Create(ReturnUpdatedUser, okEnabled);
Cancel = ReactiveCommand.Create(() => { });
}

public ReactiveCommand<Unit, UserModel> Agree { get; }
public ReactiveCommand<Unit, Unit> Cancel { get; }
}
public partial class TosViewModel: ViewModelBase
{
public TosViewModel(...)
{
IObservable<bool> okEnabled = (IObservable<bool>)this.WhenAnyValue(
x => ,
x => );

Agree = ReactiveCommand.Create(ReturnUpdatedUser, okEnabled);
Cancel = ReactiveCommand.Create(() => { });
}

public ReactiveCommand<Unit, UserModel> Agree { get; }
public ReactiveCommand<Unit, Unit> Cancel { get; }
}
Two things. 1) I have no idea what I can put inside of the okEnabled function so that it returns a true value and 2) Instead of having okEnabled is there a way I can make the button enabled by default? I have tried putting IsEnabled="True" on the button itself, and that doesn't work when they click the agree button, it just returns and updated user like this
public UserModel ReturnUpdatedUser()
{
int userAgree;
UserAgree = true;

if (UserAgree)
{
userAgree = 1;
}
else
{
userAgree = 0;
}

UserModel updatedUser = new()
{
Id = User.Id,
FirstName = User.FirstName,
LastName = User.LastName,
Email = User.Email,
Username = User.Username,
Password = User.Password,
TosAgree = userAgree,
// CustomSettings = User.CustomSettings
};

Db.UpdateUser(updatedUser);

return updatedUser;
}
public UserModel ReturnUpdatedUser()
{
int userAgree;
UserAgree = true;

if (UserAgree)
{
userAgree = 1;
}
else
{
userAgree = 0;
}

UserModel updatedUser = new()
{
Id = User.Id,
FirstName = User.FirstName,
LastName = User.LastName,
Email = User.Email,
Username = User.Username,
Password = User.Password,
TosAgree = userAgree,
// CustomSettings = User.CustomSettings
};

Db.UpdateUser(updatedUser);

return updatedUser;
}
Want results from more Discord servers?
Add your server