The Poll2 library is a versatile tool designed to simplify the creation and management of polls within your applications. It provides an easy-to-use Poll object that encapsulates the entire poll structure, making it straightforward to integrate polls into your user interfaces.
-
Flexible Design: The Poll class extends StackPanel, offering a customizable layout for displaying poll questions, answers, and progress.
-
Rich Visuals: Enhance your polls with rich visuals, including icons for poll questions and multiple selection options.
-
User-Friendly Interface: The library offers an intuitive interface for users to interact with polls, providing a seamless experience in selecting answers.
-
Dynamic Progress Tracking: Automatically tracks and displays the progress of selected answers, making it easy to gauge the popularity of each option.
Getting Started
- Instantiate Poll: Create an instance of the Poll class by providing a list of answers and a question string.
var pollAnswers = new List<(string, int)> { ("Option A", 1), ("Option B", 2), ("Option C", 3) };
var pollQuestion = "Which option do you prefer?";
var poll = new Poll2.Poll(pollAnswers, pollQuestion);
- Integration: Add the Poll instance to your application's UI as needed.
yourUiElement.Children.Add(poll);
- Handle Click Events: Attach a callback function to handle user click events.
poll.ClickAction += (text, id, selected) =>
{
// Handle the click event, e.g., store user responses.
Console.WriteLine($"User selected option {id}: {text}, Selected: {selected}");
};
- External Selection: Optionally, you can programmatically select answers externally using the selectAnswer method.
// Select the answer with id 2 for user with id 123
poll.selectAnswer(2, 123, true);
Here's a simple example demonstrating how to create a poll:
var pollAnswers = new List<(string, int)> { ("Yes", 1), ("No", 2), ("Undecided", 3) };
var pollQuestion = "Do you enjoy coding?";
var poll = new Poll2.Poll(pollAnswers, pollQuestion);
// Add the poll to your UI element
yourUiElement.Children.Add(poll);
// Handle click events
poll.ClickAction += (text, id, selected) =>
{
Console.WriteLine($"User selected option {id}: {text}, Selected: {selected}");
};
boh